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

I am trying to create a macro variable, I could not  get my head where I am doing wrong. Getting a note 'Numeric converted to character' Please correct me. Thanks.

SASuserlot_0-1639067370644.png

data seq;
input study rx;
cards;
2 1
3 1
1 3
3 3
1 4
2 4
;
run;

data seq1;
set seq end=eof;
by rx study;
if first.rx then seq=1;
else seq+1;
if last.rx then call symput('seqnm'||left(rx),compress(put(seq,8.)));
if eof then call symput('numrx',compress(put(rx,8.)));
run;
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Use the right function for the task at hand.

 

Use CATS() to append the number to the macro variable name.

 

Use CALL SYMPUTX() as it will automatically trim leading/trailing spaces and automatically convert numbers to strings.  The only reason to ever use CALL SYMPUT() is if you really want to put leading/trailing spaces into the value of your macro variable.

 

data seq1;
  set seq end=eof;
  by rx study;
  if first.rx then seq=1;
  else seq+1;
  if last.rx then call symputx(cats('seqnm',rx),seq);
  if eof then call symputx('numrx',rx);
run;

View solution in original post

6 REPLIES 6
Reeza
Super User

 

left(rx)

 

 

You're applying a character function to the number rx so you get that message.

 

  • CALL SYMPUTX removes extra spaces automatically and allows you to specify a local/global macro variable in comparison to CALL SYMPUT.
  • Use the -l option in the PUT statement to align values to the left 

 

data seq;
input study rx;
cards;
2 1
3 1
1 3
3 3
1 4
2 4
;
run;

data seq1;
set seq end=eof;
by rx study;
if first.rx then seq=1;
else seq+1;
if last.rx then call symputx('seqnm'||put(rx, 8. -l), put(seq,8. -l));
if eof then call symput('numrx', put(rx,8. -l));
run;

 


@SASuserlot wrote:

I am trying to create a macro variable, I could not  get my head where I am doing wrong. Getting a note 'Numeric converted to character' Please correct me. Thanks.

SASuserlot_0-1639067370644.png

data seq;
input study rx;
cards;
2 1
3 1
1 3
3 3
1 4
2 4
;
run;

data seq1;
set seq end=eof;
by rx study;
if first.rx then seq=1;
else seq+1;
if last.rx then call symput('seqnm'||left(rx),compress(put(seq,8.)));
if eof then call symput('numrx',compress(put(rx,8.)));
run;

 

SASuserlot
Barite | Level 11

Thank you . It works.

Tom
Super User Tom
Super User

Use the right function for the task at hand.

 

Use CATS() to append the number to the macro variable name.

 

Use CALL SYMPUTX() as it will automatically trim leading/trailing spaces and automatically convert numbers to strings.  The only reason to ever use CALL SYMPUT() is if you really want to put leading/trailing spaces into the value of your macro variable.

 

data seq1;
  set seq end=eof;
  by rx study;
  if first.rx then seq=1;
  else seq+1;
  if last.rx then call symputx(cats('seqnm',rx),seq);
  if eof then call symputx('numrx',rx);
run;
SASuserlot
Barite | Level 11

Thank you, it works.

ballardw
Super User

@SASuserlot wrote:

I am trying to create a macro variable, I could not  get my head where I am doing wrong. Getting a note 'Numeric converted to character' Please correct me. Thanks.

SASuserlot_0-1639067370644.png

 

If you count columns across the line of text that starts with 5637 (the LINE referred to in the note) until you get to 43 (the COLUMN referred to in the note) you will see the R of the variable name RX is in that position. SAS is telling you that you are using a numeric variable RX with a character function. SAS is pretty nice about attempting to do what you tell it. But sometimes the default conversion to character may not yield what you want, especially when the value is not an integer. Similar applies to using character variables that look like numbers in numeric expressions.

 

Take these warnings to heart as it may mean your data is not what you actually think it is and other problems may lurk.

SASuserlot
Barite | Level 11

Thanks for detailed explanation. I will try to follow and implement if I come across this issue again.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 6 replies
  • 1177 views
  • 2 likes
  • 4 in conversation