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 !
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.