PROC IMPORT & EXPORT

PROC EXPORT DATA= all3
OUTFILE= "C:\ ... \name_of_file.xlsx"
DBMS=EXCEL REPLACE;
SHEET="data check";
RUN;

PROC IMPORT OUT= WORK.asdf
DATAFILE= ".xlsx"
DBMS=EXCEL REPLACE;
RANGE="'Administrative Data$'";
GETNAMES=YES;
MIXED=NO;
SCANTEXT=YES;
USEDATE=YES;
SCANTIME=YES;
RUN;

RETAIN statement to collapse rows

data sample;
input id $ var1 var2 var3;
datalines;
A 20 . .
A . 30 40
B 20 . .
B 20 . .
C . 10 .
C 10 . .
C . . 10
;

data sample;
set sample;
by id;
array v(3) var1-var3;
array n(3) v1-v3;
retain v1-v3;
do i = 1 to 3;
if v(i) ne . then n(i)=v(i);
end;
if last.id then do;
output;
do j = 1 to 3;
n(j)=.;
end;
end;
drop i j var1-var3;
rename v1=var1 v2=var2 v3=var3;

proc print;
run;

 

Thanks GP.

Replace all letters and numeric values into xxxx

This replaces all letters into xxxx.

data a;
q=" Licensed to ICF CONSULTING GROUP, Site 70007867. ";
prx=prxparse("s/[A-Z]/x/io");
call prxchange(prx,-1,q);
drop prx;
run;

proc print;run;

 

This replaces all letters and numeric values into xxx.

data a;
q=" Licensed to ICF CONSULTING GROUP, Site 70007867. ";
prx=prxparse("s/[A-Z,0-9]/x/io");
call prxchange(prx,-1,q);
drop prx;
run;

proc print;run;

 

Thanks, KR.

Running Winsteps from within SAS

data rasch;
input line $ 1-75;
cards;
&INST
TITLE='KNOX CUBE TEST'
NI=18
ITEM1=11
NAME1=1
PERSON=KID
ITEM=TAP
PFILE=EXAMPLE1.PF
IFILE=EXAMPLE1.IF
&END
1-4
2-3
1-2-4
1-3-4
2-1-4
3-4-1
1-4-3-2
1-4-2-3
1-3-2-4
2-4-3-1
1-3-1-2-4
1-3-2-4-3
1-4-3-2-4
1-4-2-3-4-1
1-3-2-4-1-3
1-4-2-3-1-4
1-4-3-1-2-4
4-1-3-4-2-1-4
END NAMES
;

data rasch;set rasch;
file "C:\TEMP\winstep.txt";
put (line) (100.0);
run;
option xwait xsync;
x "start C:\BIGSTEPS\BIGSTEPS.EXE C:\TEMP\winstep.txt C:\TEMP\output.txt";

 

 

PROC TTEST and created a result dataset

/*Ttest Macro*/

/*Creates a result sad data set t_test_results*/
/*Find it in a temp folder and click-open it as an excel file*/

%let dataname=sashelp.class;
%let varlist=weight height age;
%let group=sex;

proc ttest data=&dataname;
class &group;
var
&varlist
;
ods output statistics=kaz1 ttests=kaz2 equality=kaz3;
run;

data kaz3b;
set kaz3;
if ProbF < 0.05 then unequal=1;
if unequal=1;
keep Variable unequal;
run;
proc sort;by Variable ;run;
proc sort data=kaz2;by Variable ;run;
data both;
merge kaz2 kaz3b;
by Variable ;
if unequal ne 1 then unequal=0;
flag=0;
if unequal=0 and variances="Equal" then flag=1;
if unequal=1 and variances="Unequal" then flag=1;
if flag=1;

SIG=" ";
if Probt < 0.05 then SIG="*";

keep Variable Probt SIG variances;
run;

data kaz1b;
set kaz1;
jun=_n_;
run;
proc sort;by Variable ;run;

data t_test_results;
merge kaz1b both;
by Variable ;
this=0;
if class = "Diff (1-2)" then this=1;
if this =1 then do;
probt2=probt;
SIG2=SIG;
variances2=variances;
end;

keep Variable Class mean N probt2 sig2 variances2;

run;

 

Example: how to use ODS in PROC GLIMMIX or other procs

/*Use proc GLIMMIX to run an OLS regression
and saves results (parameter estiamtes) in a
data set named "john" using ODS*/
proc glimmix data=sashelp.class;
model height=weight /dist=normal link=identity solution;
ods output ParameterEstimates=john;
run;
/*Edit the result data*/
data john2;set john;

/*Create a new variable that indicates
the level of significance*/

/*Do not forget to specify a value length*/
length asterisk $ 3;

if Probt < 0.10 then asterisk="~";
if Probt < 0.05 then asterisk="*";
if Probt < 0.01 then asterisk="**";
if Probt < 0.001 then asterisk="***";

run;

/NOW FIND john2 in a work directory and right-click it
to open with Excel*/

/*You can also see this by PROC PRINT*/
proc print data=john2;
run;