Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- *Macro to sort the ds by nvar;
- %macro sort (ds,nvar);
- proc sort data = &ds;
- by &nvar;
- run;
- %mend;
- *Recall the macro;
- %sort(project.Product_dim,Product_ID);
- %sort(project.Product_list,Product_ID);
- %sort(project.Shipped,Product_ID);
- *Format;
- proc format;
- value $prod_line "Children"="CH"
- "Clothes & Shoes"="CL_SH"
- "Outdoors"="OU"
- "Sports"="SP"
- ;
- value $country " "="_Missing_"
- "AU"="Australia"
- "BE"="Belgium"
- "CA"="Canada"
- "DK"="Denmark"
- "ES"="Spain"
- "FR"="France"
- "GB"="Great Britain"
- "NL"="Netherlands"
- "NO"="Norway"
- "PT"="Portugal"
- "SE"="Sweden"
- "US"="United States"
- ;
- run;
- *Create permanent library;
- libname project "C:\Users\Irene\Desktop\STATISTICAL SCIENCES UNIBO\Statistical Software\Progetto";
- *Final Dataset;
- data project.report;
- merge project.Product_dim project.Product_list project.Shipped;
- by Product_ID;
- keep Product_ID Product_line Product_name supplier_country ship_date quantity price price_num price_cat tot;
- format Product_line $prod_line. ship_date DDMMYYD10. supplier_country $country.;
- price_num=input(price,Dollar8.2);
- if price_num=. then price_cat='';
- else if price_num <=10.35 then price_cat='1';
- else if price_num>10.35 and price_num<=21.35 then price_cat='2';
- else if price_num>21.35 and price_num<=46.85 then price_cat='3';
- else if price_num>46.85 then price_cat='4';
- tot=price_num*quantity;
- run;
- *table quantile;
- ods html close;
- ods pdf file="C:\Users\Irene\Desktop\STATISTICAL SCIENCES UNIBO\Statistical Software\Progetto\report_quantile.pdf";
- proc means data=project.report q1 median q3;
- var price_num;
- output out=project.report2;
- run;
- ods pdf close;
- ods html ;
- *Remove missing;
- data project.report_missing;
- set project.report;
- where quantity ne .;
- run;
- %sort(project.report,supplier_country);
- *Summary statistics;
- proc means data = project.report noprint;
- by supplier_country;
- var price_num;
- output out = project.report_trial
- mean = mn
- std = sd
- min = inf
- max = sup
- ;
- run;
- %sort(project.report_missing,product_id ship_date);
- *Dataset with total expenditure;
- data project.f_purchase;
- set project.report_missing;
- by product_id;
- total_expenditure=price_num*quantity;
- format total_expenditure dollar8.2;
- if first.product_id then output;
- keep Product_ID quantity price total_expenditure supplier_country ;
- run;
- *Dataset test;
- data project.test;
- set project.f_purchase;
- keep total_expenditure supplier_country expenditure_cat;
- format expenditure_cat $6.;
- if total_expenditure=. then expenditure_cat='';
- else if total_expenditure <50 then expenditure_cat="Low";
- else if total_expenditure <100 then expenditure_cat="Medium";
- else expenditure_cat="High";
- run;
- *table fisher;
- ods html close;
- ods pdf file="C:\Users\Irene\Desktop\STATISTICAL SCIENCES UNIBO\Statistical Software\Progetto\fs.pdf";
- proc freq data=project.test;
- table supplier_country*expenditure_cat / fisher;
- run;
- ods pdf close;
- ods html;
- *table summary statistics;
- ods html close;
- ods pdf file="C:\Users\Irene\Desktop\STATISTICAL SCIENCES UNIBO\Statistical Software\Progetto\report_trial_2.pdf";
- title'Summary Statistics of prices by country';
- options nodate nonumber;
- proc report data=project.report_trial missing
- style(report)=[rules=groups]
- style(header)=[font_face=times font_weight=bold font_size=8pt]
- style(column)=[font_face=times font_size=7pt]
- ;
- column supplier_country _freq_ mn sd inf sup;
- define supplier_country /order 'Country' STYLE(column)=[cellwidth=2 CM just=center font_weight=bold];
- define _freq_ /display 'N. of Purchase' STYLE(column)=[cellwidth=2 CM just=center];
- define mn /display 'Mean' STYLE(column)=[cellwidth=2 CM just=center];
- define sd /display "Standard Deviation" STYLE(column)=[cellwidth=2 CM just=center];
- define inf /display "Minimum" STYLE(column)=[cellwidth=2 CM just=center ];
- define sup /display "Maximum" STYLE(column)=[cellwidth=2 CM just=center];
- endcomp;
- run;
- title;
- ods pdf close;
- ods html ;
- *---------------------*;
- *table var grouped by product_line, without missing;
- ods listing close;
- ods pdf file="C:\Users\Irene\Desktop\STATISTICAL SCIENCES UNIBO\Statistical Software\Progetto\report_trial_1.pdf";
- options nodate nonumber;
- proc report data=project.report_missing missing
- style(report)=[rules=groups]
- style(header)=[background=white font_face=times font_weight=bold font_size=8pt]
- style(column)=[font_face=times font_size=7pt]
- ;
- column Product_ID Product_line Product_name supplier_country ship_date quantity price price_cat;
- define Product_line /order noprint 'Line' STYLE(column)=[cellwidth=2 CM just=center font_weight=bold ];
- define Product_ID /display 'ID' STYLE(column)=[cellwidth=2 CM just=center];
- define Product_name /display 'Name' STYLE(column)=[cellwidth=2 CM just=center];
- define supplier_country /display "Country" STYLE(column)=[cellwidth=2 CM just=center];
- define ship_date /display "Shipping date" STYLE(column)=[cellwidth=2 CM just=center ];
- define quantity /display "Quantity" STYLE(column)=[cellwidth=2 CM just=center];
- define price /display "Price" STYLE(column)=[cellwidth=2 CM just=center];
- define price_cat /display "Price category" STYLE(column)=[cellwidth=2 CM just=center];
- compute before product_line / style={font_face=times font_size=8pt font_weight=bold just=left};
- line '';
- line @2 "Line: " product_line $50.;
- endcomp;
- compute before _page_ / style={font_face=times font_size=14pt font_weight=bold};
- line "Purchased products grouped by line";
- endcomp;
- endcomp;
- run;
- ods pdf close;
- ods listing ;
- *---------------------*;
- *table purchase;
- ods listing close;
- ods pdf file="C:\Users\Irene\Desktop\STATISTICAL SCIENCES UNIBO\Statistical Software\Progetto\report_trial_3.pdf";title;
- options nodate nonumber;
- proc report data=project.f_purchase
- style(report)=[rules=groups]
- style(header)=[background=white font_face=times font_weight=bold font_size=8pt]
- style(column)=[font_face=times font_size=7pt]
- ;
- column Product_ID quantity price total_expenditure;
- define Product_ID /display 'ID' STYLE(column)=[cellwidth=2 CM just=center];
- define quantity /display 'Quantity' STYLE(column)=[cellwidth=2 CM just=center];
- define total_expenditure /display 'Total Expenditure' STYLE(column)=[cellwidth=2 CM just=center];
- define price /display "Price" STYLE(column)=[cellwidth=2 CM just=center];
- compute before _page_ / style={font_face=times font_size=14pt font_weight=bold};
- line "Total expenditure related to the first purchase (by shipping date)";
- endcomp;
- endcomp;
- run;
- ods pdf close;
- ods listing ;
- *---------------------*;
- *table total expenditure;
- ods listing close;
- ods pdf file="C:\Users\Irene\Desktop\STATISTICAL SCIENCES UNIBO\Statistical Software\Progetto\report_trial_4.pdf";title;
- options nodate nonumber;
- proc report data=project.project.report2
- style(report)=[rules=groups]
- style(header)=[background=white font_face=times font_weight=bold font_size=8pt]
- style(column)=[font_face=times font_size=7pt]
- ;
- column Product_ID quantity price total_expenditure;
- define Product_ID /display 'ID' STYLE(column)=[cellwidth=2 CM just=center];
- define quantity /display 'Quantity' STYLE(column)=[cellwidth=2 CM just=center];
- define total_expenditure /display 'Total Expenditure' STYLE(column)=[cellwidth=2 CM just=center];
- define price /display "Price" STYLE(column)=[cellwidth=2 CM just=center];
- compute before _page_ / style={font_face=times font_size=14pt font_weight=bold};
- line "Total expenditure related to the first purchase (by shipping date)";
- endcomp;
- endcomp;
- run;
- ods pdf close;
- ods listing ;
- *---------------------*;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement