Hello,
I try to get the following result:
From de following table:
DATA SALE; INPUT FILE $ VAR1 VAR2 VAR3 CATEGORY $; CARDS; A 02 03 10 HIGHT A 05 02 03 LOW A 06 02 01 MEDIUM A 02 06 01 MEDIUM B 10 01 06 LOW B 02 03 03 MEDIUM C 03 05 07 MEDIUM C 05 08 06 LOW C 06 10 08 LOW ; RUN;
Can someone help me ?
DATA SALE;
INPUT FILE $ VAR1 VAR2 VAR3 CATEGORY $;
CARDS;
A 02 03 10 HIGHT
A 05 02 03 LOW
A 06 02 01 MEDIUM
A 02 06 01 MEDIUM
B 10 01 06 LOW
B 02 03 03 MEDIUM
C 03 05 07 MEDIUM
C 05 08 06 LOW
C 06 10 08 LOW
;
RUN;
*Summarize to one per file/category;
proc means data=sale noprint nway completetypes;
class file category;
output out=summary (Drop=_:) sum=;
run;
*transpose to long format;
proc transpose data=summary out=temp(rename=(_name_=variable col1=value));
by file category;
run;
*assign 0 to missing values;
data temp;
set temp;
if value = . then value=0;
run;
*transpose to a wide format;
proc transpose data=temp out=want delimiter=_;
by file;
id variable category;
var value;
run;
@sasuser_8 wrote:
Hello,
I try to get the following result:
From de following table:
DATA SALE; INPUT FILE $ VAR1 VAR2 VAR3 CATEGORY $; CARDS; A 02 03 10 HIGHT A 05 02 03 LOW A 06 02 01 MEDIUM A 02 06 01 MEDIUM B 10 01 06 LOW B 02 03 03 MEDIUM C 03 05 07 MEDIUM C 05 08 06 LOW C 06 10 08 LOW ; RUN;Can someone help me ?
DATA SALE;
INPUT FILE $ VAR1 VAR2 VAR3 CATEGORY $;
CARDS;
A 02 03 10 HIGHT
A 05 02 03 LOW
A 06 02 01 MEDIUM
A 02 06 01 MEDIUM
B 10 01 06 LOW
B 02 03 03 MEDIUM
C 03 05 07 MEDIUM
C 05 08 06 LOW
C 06 10 08 LOW
;
RUN;
*Summarize to one per file/category;
proc means data=sale noprint nway completetypes;
class file category;
output out=summary (Drop=_:) sum=;
run;
*transpose to long format;
proc transpose data=summary out=temp(rename=(_name_=variable col1=value));
by file category;
run;
*assign 0 to missing values;
data temp;
set temp;
if value = . then value=0;
run;
*transpose to a wide format;
proc transpose data=temp out=want delimiter=_;
by file;
id variable category;
var value;
run;
@sasuser_8 wrote:
Hello,
I try to get the following result:
From de following table:
DATA SALE; INPUT FILE $ VAR1 VAR2 VAR3 CATEGORY $; CARDS; A 02 03 10 HIGHT A 05 02 03 LOW A 06 02 01 MEDIUM A 02 06 01 MEDIUM B 10 01 06 LOW B 02 03 03 MEDIUM C 03 05 07 MEDIUM C 05 08 06 LOW C 06 10 08 LOW ; RUN;Can someone help me ?
Thanks !
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.