BookmarkSubscribeRSS Feed
kirkends
Fluorite | Level 6

I am new to SAS and need some help reshaping a data set and am not sure where to start. My data set is an excel. I think I need to use an Array but am not sure how to logic it. 

 

HAVE 

Unique ID INOUTN/AN/O
11, 2, 3, 4, 5, 6, 7, 10, 11, 13, 15, 16, 17, 21, 22, 24, 283014, 18, 19, 20, 23, 25, 26, 27, 298, 9, 12
230   
31, 2, 3, 4, 5, 6, 7, 9, 10, 11, 13, 15, 16, 17, 21, 22, 28 14, 18, 19, 20, 24, 25, 26, 27, 298, 12, 23
41, 2, 3, 4, 5, 10, 11, 13, 14, 15, 16, 17, 22, 28 18, 19, 20, 21, 25, 26, 27, 296, 7, 8, 9, 12, 23, 24
51, 2, 3, 4, 5, 6, 7, 8, 9, 11, 13, 15, 16, 17, 20, 22, 23, 281014, 18, 19, 24, 25, 26, 27, 2912, 21

 

Want

 

uniqueIDV1V2V3V4V5V6V7V8V9V10V11V12V13V14V15V16V17V18V19V20V21V22V23V24V25V26V27V28V29.....V30     
1INININININININN/ON/OININN/OINN/AINININN/AN/AN/AN/AN/AN/AN/AN/AN/AN/AINN/AN/A     
2.............................IN     
3INININININININN/OINININN/OINN/AINININN/AN/AN/OININN/ON/ON/AN/AN/AINN/AN/A     
4INININININN/ON/ON/ON/OININN/OINN/AINININN/AN/AINN/OININN/AN/AN/AN/AINN/AN/A     
5INININININININININOUTINN/OINN/AINININN/AN/AINN/OININN/AN/AN/AN/AINN/AN/A     
2 REPLIES 2
ballardw
Super User

Before going about reshaping the data you might describe just how you intend to use the resulting data set.

There may be better ways to reshape it based on intended use.

 

Have you created a SAS dataset?

Are the variable names as you show the column headings? I ask because by default SAS will not like space or / characters in variable names.

 

Something like this should work but again, how your actually intend to use the data this may not be the best case.

data want;
   set have;
   array v(30) $ 5;
   do i=1 to countw(in);
      pos=input(scan(in,i),2.);
      v[pos]='IN';
   end;
   do i=1 to countw(out);
      pos=input(scan(out,i),2.);
      v[pos]='OUT';
   end;
   do i=1 to countw(n_a); /*what ever the actual name of the N/A becomes*/
      pos=input(scan(n_a,i),2.);
      v[pos]='N/A';
   end;
   do i=1 to countw(n_o); /* same note about variable name*/
      pos=input(scan(n_o,i),2.);
      v[pos]='N/O';
   end;
   keep uniqueid v: ;
run;
kirkends
Fluorite | Level 6

@ballardw I have about 7 data sets all answering the same questions, but all entered in unique and creative formats. This is the most common entry layout but it is not the same across each dataset. I am hoping to reshape the dataset into the requested final format, merge all 7 sets (for sharing) and eventually provide frequency counts for IN OUT N/A N/O per V#. 

 

 

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

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