Help using Base SAS procedures

renaming a variable

Reply
Contributor
Posts: 57

renaming a variable

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.
Super Contributor
Super Contributor
Posts: 3,174

Re: renaming a variable

Check your DATA statement, also your SAS log should identify the problem.

Scott Barry
SBBWorks, Inc.
Contributor
Posts: 57

Re: renaming a variable

I fixed it.

Instead of renaming it I assigned it to pid.

instead of rename &idvar=pid;

I used pid=&idvar;

Sandhya.
Super Contributor
Super Contributor
Posts: 3,174

Re: renaming a variable

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.
Ask a Question
Discussion stats
  • 3 replies
  • 137 views
  • 0 likes
  • 2 in conversation