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

tryiing to conver  a num var (id) to char by writing this step:

data new;

set old (rename=(id=id1));

id=put(id1,2.);

drop id1;

run;

and  i am getting asterix in the column of id. Does anyone know  why?

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

You will get an asterisk whenever the numeric value is 100 or more ... so that it won't fit in a 2. format.  You could guess at the right width to use:

id = put(id1, 4.);

Or, you could run a PROC MEANS and see what the maximum value is.

Good luck.

View solution in original post

5 REPLIES 5
dcruik
Lapis Lazuli | Level 10

Looks like you're using a numeric format in your put statement.  Also, when converting a numeric variable to character, often times it gives you leading blanks.  Try modifying your code to this:

data new;

set old (rename=(id=id1));

id=strip(put(id1,$2.);

drop id1;

run;

Hope that helps!

Astounding
PROC Star

You will get an asterisk whenever the numeric value is 100 or more ... so that it won't fit in a 2. format.  You could guess at the right width to use:

id = put(id1, 4.);

Or, you could run a PROC MEANS and see what the maximum value is.

Good luck.

Tal
Pyrite | Level 9 Tal
Pyrite | Level 9

right!

i thought the numbers were two digit numbers and was expecting so  but  it turns out they were all between 100 and  500 so my formatting was not correct .

Thanks Smiley Happy

Thank you all guys for the  quick  reponse

Steelers_In_DC
Barite | Level 11

Here you go:

data have;

infile cards dsd;

input num;

cards;

1

;

run;

data want(rename=(num2=num));

set have;

num2 = put(num,8.);

drop num;

run;

jsasusr
Fluorite | Level 6

The last time I did this, I didn't create a new table I just kept the old, so I wrote:

data oldtable;

set oldtable;

newvar=put(oldvar, 2.);

drop oldvar;

run;

(Actually I dropped the old variable in a different step because I needed it in another join. 

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!

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.

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
  • 5 replies
  • 1728 views
  • 6 likes
  • 5 in conversation