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

Dear All;

I have the following dataset:

data have;

input ID Var;

datalines;

10     550     

20     440        

;


where Var is a numeric variable, I would like to transform it to a character variable and obtain the following

data want;

input ID Var;

datalines;

10     5-50     

20     4-40        

;


This my unsuccessful attempt:


data want;

set have;

Var1 = put(Var,10.);

run;

data want; set want;

if Var1 = '550' then Var1 = '5-50';

if Var1 = '440' then Var1 = '4-40';

run;


Any help would be highly appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Change your put statement to use the -l option, it will align your variable to the left.

For your conversion you may want to use substr/catt functions instead of harding it.

Var1 = put(Var,10. -l);

View solution in original post

1 REPLY 1
Reeza
Super User

Change your put statement to use the -l option, it will align your variable to the left.

For your conversion you may want to use substr/catt functions instead of harding it.

Var1 = put(Var,10. -l);

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 358 views
  • 0 likes
  • 2 in conversation