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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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