BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

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.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 344 views
  • 0 likes
  • 2 in conversation