BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
sasuser_8
Obsidian | Level 7

Hello,

I try to get the following result:

 

2023_10_13_12_26_25_Window.jpg

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 ?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
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:

 

2023_10_13_12_26_25_Window.jpg

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 ?

 

 


 

View solution in original post

2 REPLIES 2
Reeza
Super User
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:

 

2023_10_13_12_26_25_Window.jpg

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 ?

 

 


 

sasuser_8
Obsidian | Level 7

Thanks !

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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