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 !

sas-innovate-wordmark-2025-midnight.png

Register Today!

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.


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