My data has the following variables:
SSN ($11)
Inits ($4)
City ($20)
ZipCd (8)
StateCd ($2)
The following is the code I have:
DATA WORK.XXX;
SET YYY;
IF State = 'IOWA' THEN StateCd = 'IA';
KEEP SSN -- ZipCd;
KEEP StateCd;
DROP Sex -- BirthDt;
DROP State;
Initials=CATS(Scan(Initials, -1, ','), SCAN(Initials, 1, ','));
RENAME Initials = Inits;
City = PROPCASE(City);
RUN;
I am trying to change the 'ZipCd' variable from numeric to character as well as change the length from 8 to 5. I have tried a PUT function but due to the other statements in my code I am unsure on the placement of the PUT function that will allow these changes.
Thank you!
Hi @mady3,
An example of what I described in my initial response can be seen below:
data want(rename = (c_height = height));
set sashelp.class;
length c_height $ 4;
c_height = put(height,4.1);
drop height;
run;
Kind regards,
Amir.
Hi @mady3,
Once a variable's type has been set it cannot be changed, so you'll have to create another variable, e.g. c_ZipCd as character, assign it the value held in ZipCd, drop ZipCd and then rename your c_ZipCd to ZipCd.
Kind regards,
Amir.
Hi @mady3,
An example of what I described in my initial response can be seen below:
data want(rename = (c_height = height));
set sashelp.class;
length c_height $ 4;
c_height = put(height,4.1);
drop height;
run;
Kind regards,
Amir.
Hi Amir,
I appreciate your help!
Best 🙂
Hi @mady3,
No problem, happy to help when I can. Does that mean your problem has been addressed or do you still have an issue?
If it is addressed then you can mark a response as the solution, otherwise post details of the issue.
Kind regards,
Amir.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.