BookmarkSubscribeRSS Feed
wschnell1
Calcite | Level 5

Hi,

I have several variables and would like to change the format of one of the variables. I have tried the following code but am having some trouble getting it to work

The variable I am trying to change to format 8. is called firmid

data sub_sample_1986;

     format firmid 8.;

     run;

Any help is appreciated

Cheers

5 REPLIES 5
Tal
Pyrite | Level 9 Tal
Pyrite | Level 9

     Are you sure you r not missing a set statement in your code?

ballardw
Super User

Proc datasets will let you change characteristics of variables such as label and fomrat in place without creating a new data set.

proc datasets library=<library the dataset is in> ;

     modify sub_sample_1986;

          format firmid 8.; /*put as many variable name format combinations as you need here*/

run;

quit;


Tal
Pyrite | Level 9 Tal
Pyrite | Level 9

is your code ballardw as efficient as this below?  Just curious

data sub_sample;

modify sub_sample;

format firmid 8.; run;

ballardw
Super User

Define "efficient" in this case. I think using MODIFY you're going through all of the observations in the data set, so execution time is going to depend on the number of records. With Proc datasets only the data set descriptor is affected and it takes basically the same amount of time to run with 10 records or 10billion.

Modify is intended to modify, append or delete observations from a data set, in other words change the content.

It is worth remembering the note in the SAS documentation:

Damage to the SAS data set can occur if the system terminates abnormally during a DATA step that contains the MODIFY statement. 

Observations in native SAS data files might have incorrect data values, or the data file might become unreadable.

Proc Datasets as called in this above manner only changes the descriptions of the variables: name, format, informat or label and will not actually change values or the number of observations.

Tal
Pyrite | Level 9 Tal
Pyrite | Level 9

right,he just wanted to change the format not modify the entire data.

Thanks for the explanation

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