BookmarkSubscribeRSS Feed
Sandhya
Fluorite | Level 6
Hi,

I have a variable from a data set which I receive everyday from different programmers. Some would id number. Some would have it as character and some numeric. My program should check the format of the output and name it PID.

For this I tried this code but the renaming happens anyway.

data data;
set &data;
if (vformatn(&idvar) eq '$') then do;
pid=input(&idvar, 8.);
end;
else do;
rename &idvar=pid;
end;
run;

So the result is the character to numeric conversion never stays.

Please suggest something.

Thank you,
Sandhya.
3 REPLIES 3
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Check your DATA statement, also your SAS log should identify the problem.

Scott Barry
SBBWorks, Inc.
Sandhya
Fluorite | Level 6
I fixed it.

Instead of renaming it I assigned it to pid.

instead of rename &idvar=pid;

I used pid=&idvar;

Sandhya.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Do consider that the RENAME statement is not a type that has conditional execution. Your SAS variable rename process will occur regardless of the DO/END code piece.

It appears you may be using SAS macro language, so you may explore converting the DATA step DO/END to a macro %DO/%END, if appropriate.

Scott Barry
SBBWorks, Inc.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 3 replies
  • 912 views
  • 0 likes
  • 2 in conversation