- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
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;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you . It works.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you, it works.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for detailed explanation. I will try to follow and implement if I come across this issue again.