Variable format

Reply
Occasional Contributor
Posts: 15

Variable format

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

Super Contributor
Super Contributor
Posts: 440

Re: Variable format

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

Super User
Posts: 10,483

Re: Variable format

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;


Super Contributor
Super Contributor
Posts: 440

Re: Variable format

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

data sub_sample;

modify sub_sample;

format firmid 8.; run;

Super User
Posts: 10,483

Re: Variable format

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.

Super Contributor
Super Contributor
Posts: 440

Re: Variable format

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

Thanks for the explanation

Ask a Question
Discussion stats
  • 5 replies
  • 215 views
  • 1 like
  • 3 in conversation