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.

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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