Help using Base SAS procedures

Different formats according to years.

Reply
Contributor
Posts: 25

Different formats according to years.

There are lots of data for years.(from 1990 to 2015)

A survey is done every 6 months.

Different options were used same variables for each period

I want to get a table with proc tabulate for any variables, I have to use the  separately for each period and each year then combine output.

I want to combine/append all these data sets.

Variable names are the same for each period/years but different options for the years.

for example

This format used between 1990-2000

PROC FORMAT;

VALUE VARIABLE_01

0='Very satisfied'

1='Satisfied'

2='Neither nor unsatisfied';

This format used between 2000-2005

PROC FORMAT;

VALUE VARIABLE_01

11='Very satisfied'

12='Satisfied'

13='Neither nor unsatisfied'

14='Not satisfied'

45='Not satisfied at all'

;

This format used from 2005

PROC FORMAT;

VALUE VARIABLE_01

01='Very satisfied'

02='Satisfied'

03='Neither nor unsatisfied'

04='Not satisfied'

05='Not satisfied at all'

06='No idea';

when using proc tabulate use the following format for  years less then 2000.

is it possible?

I would like to summary tables combine the data with a single proc tabulate.

best regards..

Super User
Posts: 5,097

Re: Different formats according to years.

If it were me, I would change the data.  For variable 1, if the answer was 1 and the survey year was 1991, I would change the value from 1 to 199101.  You end up with a six-digit value, and just a single format would be needed.  After that, PROC TABULATE is easy.

Good luck.

Super User
Posts: 10,549

Re: Different formats according to years.

If you didn't have multiple meanings for the same value: 1 in 1990 with a different meaning in 2005 you could have just modified the format as you multiple values can map to the same formatted value and Proc Tabulate will use the formatted value (though the display order might be an issue sometimes).

But if you have many variables doing this I agree that Astounding's approach I likely a better solution in the long run. It will have the added benefit that values from a later dataset wouldn't have the values of the format and the appearance of the "raw" value would be a reminder for validation and update of the format for combined data.

Another option would be to create Text versions of the variables using the format for the appropriate year and then combining the data and using only the text values. Which could seriously complicate appearance orders in Tabulate output.

Super User
Posts: 17,949

Re: Different formats according to years.

Is your variable character or numeric? If your variable is character you don't appear to have an overlap.

The last format looks character but the first two look to be numeric.

Otherwise as Astounding has mentioned you should map all variables to one system.

Contributor
Posts: 25

Re: Different formats according to years.

Hi,

There are differences as of year ,As can be understood from the format.

Some years the characters, some years numeric.

take based on the format of the final year(2015) of the past year I have to edit accordingly.

but there are different codes.

should I prepare most wide format which included the whole years?

Is there something like this?

if year=1991 then use format...

Super User
Posts: 10,549

Re: Different formats according to years.

If you are going to combine the data into a single dataset you will need to pick whether the variable is going to be numeric or character.

Formats are not conditional. A variable may only have one format associated at a given time.

Super User
Posts: 17,949

Re: Different formats according to years.

I would recommend creating a new numeric variable, the numeric variable would allow the results to sort correctly for display in proc tabulate whereas the character variable would sort alphabetically.

PROC FORMAT;

VALUE satisfaction_fmt

0, 11='Very satisfied'

1, 12='Satisfied'

2, 13='Neither nor unsatisfied'

14='Not satisfied'

45='Not satisfied at all'

99='No idea'

;

IN THE DATASTEP:

if year=2005 then do;

if variable_orig='01' then variable_new=11;

else if variable_orig='02' then variable_new=12;

else if variable_orig='03' then variable_new=13;

else if variable_orig='04' then variable_new=14;

else if variable_orig='05' then variable_new=15;

else if variable_orig='06' then variable_new=99;

end;

format variable_new satisfaction_fmt.;

Valued Guide
Posts: 3,208

Re: Different formats according to years.

You could  use the inputc for converting the data according to different years.  SAS(R) 9.4 Functions and CALL Routines: Reference, Third Edition

This is possible because the used format is not a static one but can be a variable deduced from in your case years.

You could define a format using also the fcmp options Base SAS(R) 9.4 Procedures Guide, Third Edition

The FCMP approach has some limitations as not being of the same kind (compatible) with classic SAS functions Base SAS(R) 9.4 Procedures Guide, Third Edition The report procedures is supporting it.   

---->-- ja karman --<-----
Ask a Question
Discussion stats
  • 7 replies
  • 259 views
  • 1 like
  • 5 in conversation