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

Hello:

 

I got error message from Log when I use proc sql to create macro.  Why it doesn't work? 

 

data temp;

set have;

if substr(name,1, 6)='nad_dx' then N1=1;

else if substr(name,1, 8)='nad_cert' then N2=1;

run;

 

Proc means data=temp;

format _numeric_ best2.0;

Var _numeric_;

Output out=want sum =;

Run;

 

proc sql;

select N1 into: cnt1 from count;

select N2 into: cnt2 from count;

quit;

 

data rename;

set test;

rename nad_dx_1-nad_dx_&cnt1=bd_dx_1-bd_dx_&cnt1;

rename nad_cert_1-nad_cert_&cnt2=bd_dx_cert_1-bd_dx_cert_&cnt2;

run;

 

137 data rename;

138 set test;

139 rename nad_dx_1-nad_dx_&cnt1=bd_dx_1-bd_dx_&cnt1;

SYMBOLGEN: Macro variable CNT1 resolves to              18

NOTE: Line generated by the macro variable "CNT1".

1 nad_dx_                18

                                  --

                                 73

                                 200

ERROR: Missing numeric suffix on a numbered variable list (nad_dx_1-nad_dx_).

SYMBOLGEN: Macro variable CNT1 resolves to 18

NOTE: Line generated by the macro variable "CNT1".

1 bd_dx_                   18

                                  --

                                  22

                                  200

ERROR: Missing numeric suffix on a numbered variable list (bd_dx_1-bd_dx_).

ERROR 73-322: Expecting an =.

ERROR 200-322: The symbol is not recognized and will be ignored.

ERROR 22-322: Syntax error, expecting one of the following: a name, ;.

140 rename nad_cert_1-nad_cert_&cnt2=bd_dx_cert_1-bd_dx_cert_&cnt2;

SYMBOLGEN: Macro variable CNT2 resolves to 16

NOTE: Line generated by the macro variable "CNT2".

1 nad_cert_          16

                              --

                             73

                             200

ERROR: Missing numeric suffix on a numbered variable list (nad_cert_1-nad_cert_).

SYMBOLGEN: Macro variable CNT2 resolves to              16

NOTE: Line generated by the macro variable "CNT2".

1 bd_dx_cert_               16

                                       --

                                      22

                                      200

ERROR: Missing numeric suffix on a numbered variable list (bd_dx_cert_1-bd_dx_cert_).

ERROR 73-322: Expecting an =.

ERROR 200-322: The symbol is not recognized and will be ignored.

ERROR 22-322: Syntax error, expecting one of the following: a name, ;.

141 run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Oligolas
Barite | Level 11

because the values cnt1 and cnt2 contain spaces. Use %cmpres

 

 

________________________

- Cheers -

View solution in original post

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

N1 is a numeric value, therefore it has a default length of 8.  When this goes into a macro variable which is character, it gets converted to string as:

"      18"

So when this is applied:

nad_dx_&cnt1

You get:

nad_dx_      18

which is not valid.  As I mentioned in your other post, there are better methods to do this whole process.

https://communities.sas.com/t5/SAS-Procedures/Call-Symputx-doesn-t-work/m-p/367195#M64905

Oligolas
Barite | Level 11

because the values cnt1 and cnt2 contain spaces. Use %cmpres

 

 

________________________

- Cheers -

ybz12003
Rhodochrosite | Level 12

Thank you so much.  It works.

Reeza
Super User

Create the macro variable correctly in the first place without spaces. 

 

proc sql;
select N1 into: cnt1 TRIMMED from count;
select N2 into: cnt2 TRIMMED from count;
Quit;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 1857 views
  • 1 like
  • 4 in conversation