BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Altal
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

View solution in original post

3 REPLIES 3
Reeza
Super User

You could add a parameter check to your macro

if id="" then do nothing

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

Tom
Super User Tom
Super User

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;

Altal
Calcite | Level 5

Thank you guys!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 3 replies
  • 1349 views
  • 3 likes
  • 3 in conversation