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

Hi,

Can anyone suggest me any function in SAS similar to Text function in excel. I need to change the format of the coulmn in SAS.

For eg from excel point of view, I would like to do something like this TEXT(A1,"00000").

Let me know if anything can done like this in SAS. Thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
AmitRathore
Obsidian | Level 7

Hi Vishan,

If I understood you correctly, you cannot change a specific value from numeric to character. If need one has to apply the format to the variable and it applies to all values within that variable.

So if you have numeric column(right aligned) you can convert the same to character(left aligned) by PUT function.

data test;

  x = 111; output;

  x = 222; output;

run;

data test1;

  set test;

  y = put(x, 3.);

  put y =;

run;

Hope this suffices your requirement. Smiley Happy

Br,Amit

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

You would need to provide some more information, preferable before and after data in the form of a datastep.  The reason is you can easily change the format of a column assuming that that column has data which is acceptable to the new format e.g:

data have;

     length col $5;

     col="123"; output;

     col="456"; output;

run;

data want;

     set have;

     col_to_num=input(col,best.);

     format col_to_num 6.;

run;

However, if your character data contained letters or non-numeric you would get missing, or have to error handle it.

AmitRathore
Obsidian | Level 7

Hi Vishan,

If I understood you correctly, you cannot change a specific value from numeric to character. If need one has to apply the format to the variable and it applies to all values within that variable.

So if you have numeric column(right aligned) you can convert the same to character(left aligned) by PUT function.

data test;

  x = 111; output;

  x = 222; output;

run;

data test1;

  set test;

  y = put(x, 3.);

  put y =;

run;

Hope this suffices your requirement. Smiley Happy

Br,Amit

vishal09
Calcite | Level 5

Hi,

Thanks a lot. This worked for me. Smiley Happy

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
  • 3 replies
  • 27463 views
  • 0 likes
  • 3 in conversation