BookmarkSubscribeRSS Feed
Garik
Obsidian | Level 7

Hi, there.

 

I have such question.

If I have sas code as is below and the result should be as shown at the end, what to write instead of the question marks. 

 


data input_method;

input  GG$    HH$     ????????????????;

 

datalines;
G A R I K
H A K O B Y A N
;
run;

////////////////////////////////////////////////////

GG  HH

G   H

A    A

R   K

I    O 

K   B

     Y

     A

     N

5 REPLIES 5
Garik
Obsidian | Level 7

if dataline contanins huge amount of lines.

 

is there any way to do so or not?

Tom
Super User Tom
Super User

Looks like a simple transpose problem. Not sure where you came up the name for columns in the resulting output.  This will just name them row1, row2, etc .

 

data raw ;
  length row col 8 value $20 ;
  infile cards col=cc length=len truncover ;
  row+1;
  do col=1 by 1 until ( cc > len) ;
    input value @ ;
    output;
  end;
cards;
G A R I K
H A K O B Y A N
Another set of values
;

proc sort data=raw;
  by col row ;
run;

proc transpose data=raw prefix=row out=want(drop=_name_);
  by col ;
  id row ;
  var value ;
run;
Astounding
PROC Star

Here's one approach.  You may benefit by adding LENGTH statements for GG and HH:

 

data input_method;

infile datalines truncover;

input GG_list & $60. / HH_list & $60.;

do _n_=1 by 1 until (GG=' ' and HH=' ');

GG = scan(GG_LIST, _n_);

HH = scan(HH_LIST, _n_);

if GG > ' ' or HH > ' ' then output;

end;

keep gg hh;

datalines;

G A R I K

H A K O B Y A N

;

 

ballardw
Super User

This will do what you are requesting but is not going to be easily extended to a generic use. The 14 would have to be replaced by the length of the longest line and the better be a space between each character. If the spaces came from a double-byte character set then maybe you wouldn't need the "by 2" bit depending on your current session encoding.

data input_method;
   infile datalines n=2 truncover;
   do i=1 to 14 by 2;
      input #1 @i GG $  #2 @i  HH $ @@ ;
      output;
   end;
   drop i;
input;
datalines;
G A R I K      
H A K O B Y A N
;
run;

If you have an actual application for this then you might look at reading the entire line(s) into variables and parsing.

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 5 replies
  • 832 views
  • 4 likes
  • 5 in conversation