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: 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!

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.

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