BookmarkSubscribeRSS Feed
Ivy
Quartz | Level 8 Ivy
Quartz | Level 8

 

Hello,  

 

I tried to use the following statement to create two macro variables.  However it gave me the error. May you please help ? Thanks. 

 

ERROR: Symbolic variable name 1 must begin with a letter or underscore.
NOTE: Invalid argument to function SYMPUT('1','157') at line 28 column 6.
cohort=flatiron cnnt=157 _ERROR_=1 _N_=1
ERROR: Symbolic variable name 2 must begin with a letter or underscore.
NOTE: Invalid argument to function SYMPUT('2','157') at line 28 column 6.
cohort=trial cnnt=157 _ERROR_=1 _N_=2

 

 

 

data _null_;
set cntt;
call symput(strip(cohort), strip(count));
run;

 

Obs cohort count

1 flatiron 157
2 trial 157

2 REPLIES 2
Rick_SAS
SAS Super FREQ

If count is a numerical variable then you can put the value in a macro variable 'cohort' by using

call symput("cohort", count);

 

data _null_;
count = 15;
call symputx("cohort", count);
run;
%put &=cohort;
Tom
Super User Tom
Super User

The error messages do not seem to be related to the code you posted.

Let's turn your listing into a dataset.

data cntt ;
  input cohort :$32. count ;
cards;
flatiron 157
trial 157
;

And then try your code.

Let's simplify things by using the modern CALL SYMPUTX() function instead of archaic CALL SYMPUT() function.

data _null_;
  set cntt;
  call symputx(cohort,count);
run;

Works fine.

2156  %put &=flatiron &=trial ;
FLATIRON=157 TRIAL=157

Perhaps your COHORT variable is actual numeric with a format attached?  If so you might want to use the formatted value for the name name of the macro variable.

data _null_;
  set cntt;
  call symputx(vvalue(cohort),count);
run;

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 494 views
  • 0 likes
  • 3 in conversation