DATA Step, Macro, Functions and more

Ignoring ID statement of PROC TRANSPOSE

Accepted Solution Solved
Reply
Contributor
Posts: 62
Accepted Solution

Ignoring ID statement of PROC TRANSPOSE

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= _Smiley Happy 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


Accepted Solutions
Solution
‎10-25-2013 06:09 PM
Super User
Super User
Posts: 7,060

Re: Ignoring ID statement of PROC TRANSPOSE

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= _Smiley Happy 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;

View solution in original post


All Replies
Super User
Posts: 19,822

Re: Ignoring ID statement of PROC TRANSPOSE

You could add a parameter check to your macro

if id="" then do nothing

else create a new macro variable id2 ->id=&id

Solution
‎10-25-2013 06:09 PM
Super User
Super User
Posts: 7,060

Re: Ignoring ID statement of PROC TRANSPOSE

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= _Smiley Happy 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;

Contributor
Posts: 62

Re: Ignoring ID statement of PROC TRANSPOSE

Thank you guys!

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 312 views
  • 3 likes
  • 3 in conversation