SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
Gick
Pyrite | Level 9
data MaTab;
   input Sexe $ age $ a $ b $ c $ ;
   datalines;
F [2-10] fort1 fort2 fort1
H [10-20] fort2 fort1 fort3
F [2-10] fort1 fort1 fort1
F [30-40] fort3 fort1 fort2
H [10-20] fort2 fort1 fort1
H [30-40] fort2 fort3 fort2
H [30-40] fort1 fort3 fort1
F [2-10] fort3 fort3 fort3
;
run; 


/*I would like to have a table like:*/
data want;
   input Variable $ Mod $ a $ b $ c $ ;
   datalines;
   Sexe F somme(fort1,fort2,fort3) somme(fort1,fort2,fort3) somme(fort1,fort2,fort3) 
   Sexe H somme(fort1,fort2,fort3) somme(fort1,fort2,fort3) somme(fort1,fort2,fort3)
   age [2-10] somme(fort1,fort2,fort3) somme(fort1,fort2,fort3) somme(fort1,fort2,fort3)
   age [10-20] somme(fort1,fort2,fort3) somme(fort1,fort2,fort3) somme(fort1,fort2,fort3)
   age [30-40] somme(fort1,fort2,fort3) somme(fort1,fort2,fort3) somme(fort1,fort2,fort3)
   ;
   run;

Hi,

Note that in the final "Want" table, the sum of the strong is the percentage sum of the crossing sex and a, sex and b, sex and c. I actually get the percentage to create this table. Same approach with age.

Can someone suggest an approach or a program allowing me to have this table (want).

Thanks for your help.

Best regards,
Gick.

2 REPLIES 2
Gick
Pyrite | Level 9
Here is what I did.
ods exclude all;
proc freq data=MaTab;
table Sexe *(a b c)/ nopercent nofreq nocol out=tab1 ;
run;

data tab1;
set tab1;
variable=compress("Sexe","'n'");;
Modalite=Sexe;
run;

From here, I want to create my table for the "Sex" variable.
I will do the same method for age. Then I'll concatenate to get my "Want" table.
My difficulty is to create the table "tab1_sum" which will look like this :
data tab1_sum;
input Variable $ Modalite $ a $ b $ c $ ;
datalines;
Sexe F sum_of_pourcent(fort1,fort2,fort3) sum_of_pourcent(fort1,fort2,fort3) sum_of_pourcent(fort1,fort2,fort3)
Sexe H sum_of_pourcent(fort1,fort2,fort3) sum_of_pourcent(fort1,fort2,fort3) sum_of_pourcent(fort1,fort2,fort3)
;
run;
Then this table "tab1_sum" will be concatenate for each variable in order to have my final table (want).

Can someone help me please.

THANKS
Gick
Tom
Super User Tom
Super User

You don't show any numbers in your expected output so it is impossible to tell what "percentage sum" you want to calculate.

 

Also it looks like you have unique combinations for A, B and C so the counts of any frequency tables are going to be 1 in every combination so I am not sure what you intended to calculate.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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
  • 2 replies
  • 811 views
  • 0 likes
  • 2 in conversation