BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

Hello

What is the way to create wanted1 and wanted2 datasets from have data set?

data have;
input subgroup group $;
cards;
1703 Cars
1703 Houses
1810 Click
1910 Click
1950 Click
;
Run;
Data wanted1;
infile cards dlm=' ' dsd truncover;
input  subgroup  group1 $ group2 $;
cards;
1703 Cars Houses
1810 Click 
1910 Click
1950 Click
;
Run;

Data wanted2;
infile cards dlm=' ' dsd truncover;
input  group $ subgroup1 subgroup2 subgroup3;
cards;
Cars 1703
Houses 1703
Click 1810 1910 1950
;
Run;
2 REPLIES 2
Kurt_Bremser
Super User

Would you PLEASE test code before posting it?

 69         data have;
 70         input subgroup group;
 71         cards;
 
 NOTE: Invalid data for group in line 72 6-9.
 REGEL:     ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0                     
 72         1703 Cars
 subgroup=1703 group=. _ERROR_=1 _N_=1
 NOTE: Invalid data for group in line 73 6-11.
 73         1703 Houses
 subgroup=1703 group=. _ERROR_=1 _N_=2
 NOTE: Invalid data for group in line 74 6-10.
 74         1810 Click
 subgroup=1810 group=. _ERROR_=1 _N_=3
 NOTE: Invalid data for group in line 75 6-10.
 75         1910 Click
 subgroup=1910 group=. _ERROR_=1 _N_=4
 NOTE: Invalid data for group in line 76 6-10.
 76         1950 Click
 subgroup=1950 group=. _ERROR_=1 _N_=5
 NOTE: The data set WORK.HAVE has 5 observations and 2 variables.
Kurt_Bremser
Super User
proc transpose data=have out=wanted1 prefix=group;
by subgroup;
var group;
run;

Similar code works for the second wanted dataset, you will need the NOTSORTED option.

CFC_SAS_Communities_400x225.jpg

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

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