/* biblioteka w sas studio */ * libname dane '/shared/home/szajac2@sgh.waw.pl/PD'; %let dir=/shared/home/szajac2@sgh.waw.pl/PD; libname dane "&dir"; /* Wczytywanie danych */ DATA dane.outdata; INPUT age sex $ dept obs1 obs2 obs3; CARDS; 1 F 3 17 6 24 1 M 1 19 25 7 3 M 4 24 10 20 3 F 2 19 23 8 2 F 1 14 23 12 2 M 5 1 23 9 3 M 1 8 21 7 1 F 1 7 7 14 3 F 2 2 1 22 1 M 5 20 5 2 3 M 4 21 8 18 1 M 4 7 9 25 2 F 5 10 17 20 3 F 4 21 25 7 3 F 3 9 9 5 3 M 3 7 21 25 2 F 1 1 22 13 2 F 5 20 22 5 ; proc print; run; DATA dane.outdata2; INPUT age sex $ dept obs1 obs2 obs3; INFILE CARDS DLM=","; CARDS; 1,F,3,17,6,24 1,M,1,19,25,7 3,M,4,24,10,20 ; run; proc print; run; %LET dir=/shared/home/szajac2@sgh.waw.pl/PD; %LET url=https://sebkaz.github.io/teaching/PrzetwarzanieDanych/data/polish_names.csv; %PUT "&dir/test.csv"; filename test "&dir/test.csv"; proc http url="&url" method="get" out=test; run; proc import file=test out=dane.imiona dbms=csv replace; run; data dane.testowy; infile "&dir/test.csv" dsd firstobs=2; input name $ sex $; run; filename sample "&dir/test.csv"; data dane.testowy2; infile sample dsd firstobs=2; input name $ sex $; run; filename plik "&dir"; data _null_; file plik('wynik.txt'); set sashelp.class; put age weight height; run; proc freq data=sashelp.class; table age; run; proc freq data=sashelp.class; table age / nocum; run; proc freq data=sashelp.class; table age / nopercent nocum; run; proc freq data=sashelp.class; table sex *age; run; proc freq data=sashelp.class; table sex *age / list; run; proc freq data=sashelp.class; table sex *age / norow nocol nopercent; run; proc freq data=sashelp.class; table sex *(age weight) / norow nocol nopercent; run; Data example2; input pre $ post $ count; cards; Yes Yes 30 Yes No 10 No Yes 40 No No 20 ; run; proc freq data=example2; table pre*post /nocum; weight count; run; data example1; input x y $ z; cards; 6 A 60 6 A 70 2 A 100 2 B 10 3 B 67 2 C 81 3 C 63 5 C 55 ; run; proc freq data=example1; tables y * x/chisq; output All out=temp_chi chisq; run; Proc freq data=sashelp.heart; Tables deathcause; Run; Proc freq data=sashelp.heart; Tables deathcause / missing; Run; Proc freq data=sashelp.heart order=FREQ; Tables deathcause / missing; Run; /*agregowanie z wykorzystaniem formatu*/ proc format; value wiek low-13='Młody' 13-15='Średni' 15-high='Stary'; run; proc means data=sashelp.class nway; class age; format age wiek.; var height; output out=stat mean(height)=sredni_wzrost; run; /* RAPORTOWANIE */ proc contents data=dane.freq1; run; proc print data=dane.freq1; run; Title "tresc tytulu"; /* titlen n - nr lini wpisu*/ footnote "tresc stopki"; /* reset */ Title; Footnote; options firstobs=1 obs=5 center date number; title 'Wydruk imiona'; footnote 'testowy'; proc print data=dane.imiona; run; /*tabulate*/ Data test; Input T1 T2 T3 T4 T5 Age BU; Cards; 1 5 2 3 4 3 3 4 5 2 1 2 1 3 3 4 4 3 2 3 2 4 3 2 5 3 3 3 1 2 4 2 1 2 2 ; Run; Proc tabulate data=test; Var T1; Table T1; Run; /* domyslnie sumowanie */ Proc tabulate data=test; Var T1; Table T1 * N; Run; Proc tabulate data=test; Var T1; Table T1 * (N MEAN STD MIN MAX); Run; proc means data=test; var T1; run; Proc Tabulate Data=test; Class Age; Var T1; Table Age, T1 * (N COLPCTN); Run; Proc Tabulate Data=test; Class Age; Var T1; Table T1, Age * (N ROWPCTN); Run; Proc Tabulate Data=test; Class Age; Var T1; Table Age, T1="Group I" * (N="Count" COLPCTN="%"); Run; Proc Tabulate Data=test; Class Age; Var T1; Keylabel N="Count" COLPCTN="%"; Table Age, T1="Group I" * (N COLPCTN); Run; Proc Tabulate Data=test; Class Age; Var T1; Table Age=" ", T1="Group I" * (N="Count" COLPCTN="%") / box="Wiek"; Run; /* total add*/ Proc Tabulate Data=test; Class Age; Var T1; Table Age ALL="Grand Total" , T1="Group I" * (N="Count" COLPCTN="%"); Run; Proc format; value agefmt 1='Under 18' 2='18 - 25' 3='Over 25'; Run; Proc format; value bufmt 1='Analytics' 2='Technology' 3='Others'; Run; Proc tabulate data=test; Format Age agefmt. BU bufmt.; Class Age BU; Var T1; Keylabel N="Count" ROWPCTN="%"; Table T1="Group I", (Age * BU="Business Unit") * (N ROWPCTN * F=6.0); Run; Data test; length BU $18.; Input Location$ BU$ Sex$ Income; Cards; Delhi Analytics Male 5000 Mumbai Tech Female 45000 Delhi Analytics Male 37000 Chennai Tech Male 33000 Delhi Tech Male 5000 Chennai Analytics Male 15000 Mumbai Analytics Female 440000 Delhi Analytics Female 5000 Mumbai Tech Male 45000 Delhi Analytics Female 37000 Chennai Tech Female 33000 Delhi Tech Female 5000 Chennai Analytics Male 15000 ; Run; Proc tabulate data=test F=6.0 out=test1; Class Location BU Sex; Var Income; Table Location=" "*BU=" ", Sex * Income=" "*(N="Count" ROWPCTN="%") / Box="Location BU"; Run; %LET save_report=&dir/zapis; ods listing close; ods pdf file="&save_report/raport.pdf"; proc tabulate data=sashelp.prdsale; class country; var actual; table country , actual; run; proc contents data=sashelp.prdsal2; run; proc print data=sashelp.prdsal2 (obs=10); run; ods pdf close; ods listing; ods listing close; ods rtf file="&save_report/rap.rtf"; proc tabulate data=sashelp.prdsale; class country; var actual; table country , actual; run; ods rtf close; ods listing; ods listing close; ods html path="&save_report/web/" (url=none) frame='index.html' page='page.html' contents='cont.html' body='body.html' style=statistical; proc tabulate data=sashelp.prdsale; class country; var actual; table country , actual; run; proc tabulate data=sashelp.prdsale; class country; var actual; table country , actual; run; ods html close; ods listing; /* MACRO PROGRAMMING */ /* token -> Macro trigers */ /* %name-token and &name-token */ %PUT 'tresc komunikatu'; /* zapis do loga - jeśli pusty = new line dozwolony w dowolnym miejscu kodu SAS */ %PUT ; /* makro zmienne - obiekty zawierające dwa elementy - nazwa (dozwolone w sas od 1-32 znaki) - wartosc (tylko tekst do 65534 znakow dynamicznie przydzielana pamiec) Makro zmienne : systemowe (macro procesor) - tworzone przy starcie SAS - nie mozna usuwac */ %PUT _AUTOMATIC_; /* uzytkownika : definiowane przez uzytkownika w trakcie wykonywania kodu wartosc moze byc pusta! */ %LET waga; %LET plec=F; %PUT _USER_; options symbolgen; proc print data=sashelp.class; where sex="&plec"; run; %let plec='F'; proc print data=sashelp.class; where sex=&plec; run; %let plec=F; options symbolgen; title "Raport dla płci &plec"; proc print data=sashelp.class; where sex="&plec"; run; %let wiek=12; proc print data=sashelp.class; where age=&wiek; run; %let a=1; %let b=2; %let c=&a+&b; %put &c; %let c=%eval(&a+&b); %put &c; %let a=1.6; %let b=2.6; %let c=%sysevalf(&a+&b); %put &c; /*%substr()*/ /*%scan()*/ /*%index()*/ data w; a='Ala#ma#kota'; b=scan(a, 1, '#'); run; %let a=Ala#ma#kota; %let b=%scan(&a, 1, #); %put &b; %let a=Ala ma kota; %let b=%scan(&a, 1, %str( )); %put &b; /* str, nrstr, nrbquote */ %let a=%sysfunc(today(), yymmdd10.); %put &a; /* łączenie makro zmiennych TXT&var &varTXT TXT&varTXT &var&var2 */ %let dsn_in = accounts; %let library = work; %let proc_name = plot; data &library..&dsn_in; procedura="g&proc_name"; run; /* %MACRO macro_name; macro_code %MEND ; */ %macro raport(a, b); %if &a=12 %then %put Jest 12; %else %do; %put Nie 12; %end; %mend; %raport(15, 4); %macro copy_table(tab_in, tab_out); data &tab_out.; set &tab_in.; run; %mend; %copy_table(sashelp.class,class_C); %copy_table(sashelp.class,class_c2); %macro stats(tab_in=class_C,s = mean sum std); proc means data=&tab_in. &s.; run; %mend; %stats; %stats(); %stats(tab_in=sashelp.class, s=mean std); %stats(s=mean sum var range); /*ods output*/ /*ods trace on / listing;*/ /*ods trace off;*/ /*pierwszy model */ data df_model; set dane.imiona; ile=length(name); run; proc print data=df_model (obs=10); run; ods listing close; ods output Association=gini ParameterEstimates=bety; proc logistic data=df_test; model gender=ile; run; ods output close; ods listing;