I'm using proc transpose in a macro (part of it below); and I have ID statement included; but sometimes I don't want to pass the macro variable &ID to the macro; if I don't pass the argument for ID, SAS will give error. However, SAS will not give an error when the &Where for WHERE statement is not specified in the macro... Is there a way to tell SAS not to err when a column for ID statement is not specified in macro parameters?
the error msg given by SAS for not specifying a column name for the ID statement is
"
LINE and COLUMN cannot be determined.
NOTE 242-205: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error
has occurred.
ERROR 22-322: Syntax error, expecting one of the following: a name, _ALL_, _CHARACTER_, _CHAR_, _NUMERIC_.
ERROR: Variable NAME not found.
"
%macro WideTranspose (data=, out= ,by=, id=,where= ,list=, Prefixlist=);
.
.
.
%sort( &data, &BY);
proc transpose data=&data out=out&n (drop= _:) prefix=&prefix LET;
by &by;
var &list;
id &id;
where &where;
run;
.
%mend;
%WideTranspose (data=data,
out=out ,
by=var1 var2,
id= ,
where= ,
list=var3 var4,
Prefixlist=var3pre var4pre);
Thanks
Use macro logic to test if the user requested ID (or BY) processing.
%macro WideTranspose (data=, out= ,by=, id=,where= ,list=, Prefixlist=);
...
%sort( &data, &BY);
proc transpose data=&data out=out&n (drop= _:) prefix=&prefix LET;
%if %length(&by) %then %do;
by &by;
%end;
%if %length(&list) %then %do;
var &list;
%end;
%if %length(&id) %then %do;
id &id;
%end;
where &where;
run;
...
%mend;
You could add a parameter check to your macro
if id="" then do nothing
else create a new macro variable id2 ->id=&id
Use macro logic to test if the user requested ID (or BY) processing.
%macro WideTranspose (data=, out= ,by=, id=,where= ,list=, Prefixlist=);
...
%sort( &data, &BY);
proc transpose data=&data out=out&n (drop= _:) prefix=&prefix LET;
%if %length(&by) %then %do;
by &by;
%end;
%if %length(&list) %then %do;
var &list;
%end;
%if %length(&id) %then %do;
id &id;
%end;
where &where;
run;
...
%mend;
Thank you guys!
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.
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.