Foredrag på SAS Forum, 18. september 2013 Nyheder i SAS 9.4 for SAS programmører, Georg Morsing Program 1 * --- Alle labels kan nu bestemmes i PROC PRINT -------; proc print data=sashelp.cars label grandtotal_label='total for begge biler' sumlabel='subtotal' noobs; where make in ('Audi','BMW') and invoice > 40000; by make ; var model invoice; sum Invoice; label invoice='pris' make ='Producent'; Program 2 /* --- Ny option CUROBS til SET og MODIFY statements --- */ data piger; set sashelp.class curobs=obs; where sex='f'; obs_num=obs;
Program 3 /* --- Ændring i SCAN funktion. Ny variabel er ikke Længere 200 lang, men længden af det første argument --- */ data; Navn='Georg Morsing'; e_navn=scan(navn,2); Program 4 /* --- Ny options til PUTC og PUTN funktioner --- */ proc format; value agefmt 10-13='10-13 år' 14-16='14-16 år'; length alder alder_c alder_r $ 20; alder = putn(age,'agefmt.'); alder_c = putn(age,'agefmt.-c',20); alder_r = putn(age,'agefmt.-r',20); if _n_=1 then do; put '*' alder $char20. '*'; put '*' alder_c $char20. '*'; put '*' alder_r $char20. '*';
Program 5 /* --- Ny DOSUBL funktion til at udføre SAS kode midt i et data step ------- */ Navn='Georg'; rc=dosubl('proc sql; select count(age) into :antal from sashelp.class;'); hvor_mange= symgetn("antal"); rc=dosubl('proc sql noprint; select avg(weight) into :w from sashelp.class;'); avg_weight= symgetn("w"); if sex='f' then rc=dosubl('proc sql noprint; select avg(weight) into :w from sashelp.class where sex="f";'); if sex='m' then rc=dosubl('proc sql noprint; select avg(weight) into :w from sashelp.class where sex="m";'); avg_weight= symgetn("w"); Program 6 libname orion 'C:\Georg\SAS Forum DK 2013\SAS 9_4\Data'; data find_priser; input product_id; datalines; 210100100010 210100100011 ;
/* --- Multiple key værdier i et HASH objekt SAS 9.3 ------------- */ data prices; if _N_ = 1 then do; if 0 then set orion.price_list; declare hash price(dataset: "orion.price_list", multidata: "y"); price.definekey("product_id"); price.definedata("start_date", "end_date", "unit_sales_price"); price.definedone(); set work.find_priser; if price.find()=0 then do; output; price.has_next(result: next); do while(next = 1); price.find_next(); output; price.has_next(result: next); keep product_id start_date end_date unit_sales_price; /* --- Multiple key værdier i et HASH objekt SAS 9.4 ------------- */ data prices; if _N_ = 1 then do; if 0 then set orion.price_list; declare hash price(dataset: "orion.price_list", multidata: "y"); price.definekey("product_id"); price.definedata("start_date", "end_date", "unit_sales_price"); price.definedone(); set work.find_priser; if price.find()=0 then do; price.reset_dup(); do while(price.do_over() eq 0); output; keep product_id start_date end_date unit_sales_price;
Program 7 /* --- VBUFSIZE option er buffer størrelse til data step views --- */ /* --- Sæt VBUFSIZE til samme værdi som bufsize på input tabel --- */ proc options option=vbufsize ; data test(bufsize=1m); length text $ 400; retain text 'Meget lang text'; do I=1 to 10000000; x= round(ranuni(0)); output; proc contents data=test; data test2 / view=test2; set test; y=x*.5; Proc means data=test2; var x y; options vbufsize=1m; Proc means data=test2; var x y;
Program 8 /* --- Bevar alt i din SAS session til senere --- */ options presenv; %let navn=georg Morsing; data piger drenge; if sex='f' then output piger; else if sex='m' then output drenge; libname sasdata 'c:\temp\data'; filename programs 'c:\temp\programs.sas'; proc presenv save permdir=sasdata sascode=programs; /* --- Hent den SAS session du sluttede med sidst --- */ %include 'c:\temp\programs.sas'; Run;
Program 9 /* --- Ny system options, besked om manglende initialization ---*/ options varinitchk=note; length gruppe $ 10; options varinitchk=nonote; length gruppe $ 10; options varinitchk=warning; length gruppe $ 10; options varinitchk=error; if weihgt > 100 then gruppe='større end 100';
Program 10 title;footnote; /* --- Placer flere typer af output på samme side --- */ /* --- Eksempel 2 ----------------------------------- */ ods layout gridded columns=2; ods region; proc print data=sashelp.class; ods region; proc print data=sashelp.class; ods layout /* --- Eksempel 2 ----------------------------------- */ ods layout gridded rows=3 row_heights=(1in 2in 3in); ods region; proc print data=sashelp.class(obs=1); ods region; proc means data=sashelp.class n mean; ods region; proc print data=sashelp.class(obs=3); ods layout
Program 12 options nonumber nodate; /* -- Send rapporter og grafer direkte til Powerpoint -- */ ods powerpoint file='c:\temp\georg.ppt' style=htmlblue; proc sgplot data=sashelp.class; bubble x=age y=height size=weight / group=sex datalabel=name transparency=.3 ; yaxis grid; proc sgpanel data=sashelp.class; panelby sex; bubble x=age y=height size=weight / datalabel=name transparency=.3 ; rowaxis grid; ods powerpoint close; Program 13 /* --- Danne powerpoint slides med PROC ODSTEXT ------------------------------- */ title; ods powerpoint file='c:\temp\georg.ppt' layout=titleslide; proc odstext; p 'Denne tekst er dannet med den nye PROC ODSTEXT' / style=presentationtitle; p 'SAS Forum 2013, Georg Morsing' / style=presentationtitle; ods powerpoint layout=_null_; proc sgplot data=sashelp.class; bubble x=age y=height size=weight / group=sex datalabel=name transparency=.3 ; yaxis grid; ods powerpoint close;
Program 14 /* --- Send output til mobile enheder --- */ ods graphics; ods epub file='c:\temp\bubleplot.epub' title='analyse' options(creator='georg'); proc freq data=sashelp.class; tables age*sex / plots=freqplot nocol norow nopercent; ods epub close; Program 15 /* --- DATA Step 2, udnyt flere CPU'er --- */ data work.jmaster; do j = 1 to 10000000; output; /* Definer koden der skal køres */ proc ds2; thread r /overwrite=yes; dcl double count; dcl double k; dcl double x; method run(); set {select * from work.jmaster}; count+1; do k=1 to 100; x=k/count + k/count + k/count;
method term(); OUTPUT; endthread; quit; /* 1 thread */ proc ds2; data j1(overwrite=yes); dcl thread r r_instance; dcl double count; dcl double total; method run(); set from r_instance threads=1; total+count; enddata; quit; /* 8 threads */ proc ds2; data j8(overwrite=yes); dcl thread r r_instance; dcl double count; dcl double total; method run(); set from r_instance threads=8; total+count; enddata; quit; title;footnote; proc print data=j8(obs=5); var j count total;