Help using Base SAS procedures

Macro variable is not reconized?

Accepted Solution Solved
Reply
Super Contributor
Posts: 319
Accepted Solution

Macro variable is not reconized?

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;

 


Accepted Solutions
Solution
‎06-15-2017 08:40 AM
Frequent Contributor
Posts: 129

Re: Macro variable is not reconized?

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

 

 

________________________

- Cheers -

View solution in original post


All Replies
Super User
Super User
Posts: 7,942

Re: Macro variable is not reconized?

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

Solution
‎06-15-2017 08:40 AM
Frequent Contributor
Posts: 129

Re: Macro variable is not reconized?

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

 

 

________________________

- Cheers -

Super Contributor
Posts: 319

Re: Macro variable is not reconized?

Thank you so much.  It works.

Super User
Posts: 19,785

Re: Macro variable is not reconized?

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;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 168 views
  • 1 like
  • 4 in conversation