BookmarkSubscribeRSS Feed
erdem_ustun
Obsidian | Level 7

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..

7 REPLIES 7
Astounding
PROC Star

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.

ballardw
Super User

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.

Reeza
Super User

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.

erdem_ustun
Obsidian | Level 7

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...

ballardw
Super User

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.

Reeza
Super User

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.;

jakarman
Barite | Level 11

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 --<-----

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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