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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Amir
PROC Star

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.

View solution in original post

4 REPLIES 4
Amir
PROC Star

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.

Amir
PROC Star

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.

mady3
Fluorite | Level 6

Hi Amir, 

 

I appreciate your help!

 

Best 🙂

Amir
PROC Star

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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 4 replies
  • 786 views
  • 2 likes
  • 2 in conversation