BookmarkSubscribeRSS Feed
Patrick
Opal | Level 21

@AngelaFan wrote:

Thank you for your responses. The code works just fine. It is the macro which works funky. 


Based on the code you've posted it's almost certainly not the macro as you don't use any macro logic anywhere. 

Because the SAS code is wrapped into a macro it can be that issues surface a bit differently - but it's about issues with your other SAS code. ...and for this reason first fix and test the code before wrapping the macro around.

Kurt_Bremser
Super User

@AngelaFan wrote:

Thank you for your responses. The code works just fine. It is the macro which works funky. 


********* (redacted). Sorry for the hard word, but there is NO macro logic at all in your macro, so the macro itself CANNOT be the reason.

Remove the %macro and %mend (and the macro call), set the single parameter as a macro variable, execute the Base SAS code step-by-step, and inspect the log after each single step. Successful macro programming will ALWAYS start with getting working Base SAS code first.

AngelaFan
Calcite | Level 5
I said clearly. There is nothing wrong with the base code. If my macro is not macro, why do not you show me what is a macro. My sad teacher will be so mad because u said the macro he taught me is not macro at all. 😄😄😄
Kurt_Bremser
Super User

Run this:

%let program=XY;

proc IMPORT datafile="&win5.\&Program._Input.txt" out=PFile 
dbms=dlm replace;
delimiter='09'x;
getnames=YES;
datarow=2; 
run; 

 
data Varnames;
	set PFile(firstobs=1 obs=1);
run;

*Transpose the dataset to get colnames;
proc transpose data=Varnames(obs=1) out=Varnames1;
	var _all_;
run;


data Varnames1;
	set Varnames1;
	if Col1="PBSX-E" THEN Col1="PBSXE";
	if col1="IN.MSQ" THEN col1="IN_MSQ";
    if col1="IN.ZSTD" THEN col1="IN_ZSTD";
	if col1="OUT.MSQ" THEN col1="OUT_MSQ";
    else if col1="OUT.ZSTD" THEN col1="OUT_ZSTD";
run;

*Create macro for each colname;
proc sql noprint;
	select catx('=',_name_,col1)
	into :colnames separated by " " 
	from Varnames1;
quit;

%put &colnames;

*Final data with appriopriate column names added;
data PFile;
	set PFile(firstobs=2 rename=(&colnames));
run;

data PFile1;
set PFile(keep=ENTRY NAME COUNT SCORE MEASURE STATUS MODLSE);
run; 

*convert all variables into numeric; 
proc contents data=PFile1 out=vars(keep=name type) noprint;
data vars;
set vars;
if type=2;
newname = trim((name))|| "_n";

proc sql noprint;
select name,  newname,
       newname || '=' || name 
into :ch_list SEPARATEd by " " , :num_list separated by " " ,
     :rename_list separated by " " 
from vars;
quit;

data PFILE2;
 set PFILE1;
array ch(*) $ &ch_list;
array nu(*) &num_list;
do i=1 to dim(ch);
   nu(i) = input(ch(i),10.);
end;
drop i &ch_list;
rename &rename_list;
run; 


proc import out=F1Examinees datafile="&win9.\&Program._exs.xlsx" dbms=xlsx replace;
getnames=YES;
run;

proc sql noprint;
select AppID
into:F1count separated by " "  
from F1examinees;
quit;

***This is F1 data;
data F1;
set Pfile2;
where NAME in (&F1count.); 
run;

data F1score;
set F1(keep=Name score);
run;

proc means data=F1score mean median std min max;
var score;
output out=F1raw mean=Mean median=Median std=SD min=Min max=Max;
run;

data F1raw;
set F1raw;
form=1;
run;

*Find reliability;
data F1theta;
set F1(keep=Name MEASURE MODLSE);
run;

data F1theta;
set F1theta;
SE_squared=MODLSE*MODLSE;
run;

proc means data=F1theta mean var noprint;
var Measure SE_squared;
output out=F1out var(Measure)= mean(SE_squared)=/autoname;
run;

data F1out1;
set F1out;
form=1;
reliability=(Measure_Var-SE_squared_mean)/ Measure_Var;
run;

data new;
set F1out1;
set F1raw;
run;


data new1;
set new;
SEM=SD*sqrt(1-reliability); 
run;

*drop unnneed variables;
data var;
set new1(keep=_FREQ_ Mean Median SD Min Max Reliability SEM);
run;

data var1;
set var;
N=_FREQ_;
drop _FREQ_;
run;


proc import out=Count datafile= "&win9.\&Program._Count.xlsx" dbms=xlsx replace;
getnames=YES;
run;

data F1_final;
set Count;
if formid = "&Program.001" & score = 0 then NOP= count;
if formid = "&Program.001" & score = 1 then NPT= count;
*Nexcluded=&F1inval.;
run;

data F1_final1;
set F1_final;
set F1_allpt(rename=(count=AllPT));
set var1;
run;

data F1_final2;
retain NOP AllPT NPT N Nexcluded Mean Median SD Min Max Reliability SEM;
set F1_final1;
run;

proc transpose data=F1_final2 out=F1_PSummary;
var _all_;
run;

*Get all the valid form 2 person information;
***This is F2 data;
data F2;
set Pfile2;
if name in (&F1count.) then delete;
run;
 
data F2score;
set F2(keep=Name score);

run;

proc means data=F2score mean median std min max;
var score;
output out=F2raw mean=Mean median=Median std=SD min=Min max=Max;
run;

data F2raw;
set F2raw;
form=2;
run;

*Find reliability;
data F2theta;
set F2(keep=Name MEASURE MODLSE);
run;

data F2theta;
set F2theta;
SE_squared=MODLSE*MODLSE;
run;

proc means data=F2theta mean var noprint;
var Measure SE_squared;
output out=F2out var(Measure)= mean(SE_squared)=/autoname;
run;

data F2out1;
set F2out;
form=2;
reliability=(Measure_Var-SE_squared_mean)/ Measure_Var;
run;

data new;
set F2out1;
set F2raw;
run;


data new1;
set new;
SEM=SD*sqrt(1-reliability); 
run;

*drop unnneed variables;
data var;
set new1(keep=_FREQ_ Mean Median SD Min Max Reliability SEM);
run;

data var1;
set var;
N=_FREQ_;
drop _FREQ_;
run;

data F2_final;
NOP= &F2_OPN.;
NPT= &F2_PTN.;
Nexcluded=&F2inval.;
run;

data F2_final1;
set F2_final;
set F2_allpt(rename=(count=AllPT));
set var1;
run;

data F2_final2;
retain NOP AllPT NPT N Nexcluded Mean Median SD Min Max Reliability SEM;
set F2_final1;
run;

proc transpose data=F2_final2 out=F2_PSummary;
var _all_;
run;


************************************************************************;
****************************Final Output***************************************; 
data FinalF1F2;
set F1_PSummary F2_PSummary;
run;

proc export data=FinalF1F2 outfile="&win9.\&Program._Candidate.xlsx" dbms=xlsx replace;
run;

step-by-step and inspect the log. If it works, your macro will also work, because it does NOTHING but replacing &program with XY.

 

If there's still any problem, post the log as is into a {i} window.

AngelaFan
Calcite | Level 5
There is problem with the code. Thank you. I need the code to run many programs. That’s why I made the code chunk a macro. Thank you.
Kurt_Bremser
Super User

@AngelaFan wrote:
There is problem with the code. Thank you. I need the code to run many programs. That’s why I made the code chunk a macro. Thank you.

Surprise, surprise.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 20 replies
  • 3949 views
  • 1 like
  • 8 in conversation