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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1687 views
  • 1 like
  • 3 in conversation