Hi, I tried to find help but didnt found a good solution.
How can I merge several proc freq tables?
I will try to make sample data, but maybe the question is so easy, that it can be answered without.
My output out of a simple prc freq procedure:
Var1 Frequency 1 2
2 3
3 5
4 8
Var2 Frequency
1 1
2 2
3 7
4 1
now I just want to get 1 table where in the colums the responses 1, 2, 3, 4 and in the rows the variables are listed.
So kind of:
1 2 3 4 Var1 2 3 5 8 Var2 1 2 7 1
Thanks 🙂
Do you want a report? That is relatively simple.
data one; input Var1 Frequency; length varname $ 32.; varname = "Var1"; value=var1; datalines; 1 2 2 3 3 5 4 8 ; data two; input Var2 Frequency; length varname $ 32.; varname = "Var2"; value = var2; datalines; 1 1 2 2 3 7 4 1 ; data combined; set one two; run;
proc tabulate data=combined;
class varname value;
freq frequency;
table varname='',
value=''*n=''
;
run;
If you want a data set you have several problems, first 1,2,3 and 4 are not valid variable names. The data set Combined above is about as close as you should come. If you need to display values like that the extra stuff to have non-standard variable names like "1" is generally not worth the effort in my opinion.
Question: do these come from the same data set with different proc freq outputs? If so, show the code you are using as we can likely create the output from Proc Freq that comes closest to what you want.
You want a report or a dataset ? If you want report ,ballarw give you answer,if you want dataset try this:
data one; input Var1 Frequency; datalines; 1 2 2 3 3 5 4 8 ; data two; input Var2 Frequency; datalines; 1 1 2 2 3 7 4 1 ; data temp; merge one(rename=(var1=id Frequency=var1)) two(rename=(var2=id Frequency=var2)); by id; run; proc transpose data=temp out=want; id id; var var1 var2; run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.