BookmarkSubscribeRSS Feed
rnmishra
Calcite | Level 5

If I am not mistaken the formatted values are only displayed in SAS outputs.

Suppose I have a data set , one of the variables is STATE (State names) I have created a format to to display the state names in their abbriviated form.

Now I want to alter this data set permanently by replacing the state names by their abbr. names.

My thoughts ....to save the print out put as a new data set....not sure how I can do this.

Any suggestions!!

Thanks,

Raghu.

2 REPLIES 2
Reeza
Super User

First why do this?

Second, you can apply a format in a data step and create a new variable.

*character;

state_format=putc(state, $state_fmt.);

*Number;

state_format=putn(state, state_fmt.);

RichardinOz
Quartz | Level 8

I can't test this at the moment but in earlier versions of SAS the second parameter of putc() and putn() had to be character expressions, ie the name of the format enclosed in quotes.  Maybe SAS now automatically manages the conversion.  The syntax shown is correct for the put() function in both cases.

You can put the abbreviation back into the state column if it is also a character variable:

     state=put(state, $state_fmt.);

However, the length of the state variable will be unchanged (and longer than the abbreviation).


Richard

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 2 replies
  • 553 views
  • 1 like
  • 3 in conversation