BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
suhwan
Calcite | Level 5

I have a one column data which contains information about multiple observations.

 

Each observation starts with a first column value of  "notes".

I.E. 

 

notes

name  A1

code   B1

...

 

notes

name A2

code  B2

...

 

...

 

notes

name A200

code  B200

...

 

Is there a good way to transpose this into 200 rows?

PS. I would like to have name, code, ..., as my column variables after transposing.

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

Like this?

data HAVE;
  input COL1 $16.;
  cards;
notes
name A1
code B1
..
notes
name A2
code B2
;
run;
data WANT;
  set HAVE;
  length NAME CODE  $8;
  retain NAME;
  if COL1=:'name' then NAME=substr(COL1,6);
  if COL1=:'code' then do ;
    CODE=substr(COL1,6);
    output;
    call missing(NAME, CODE);
  end;
run;

 

View solution in original post

1 REPLY 1
ChrisNZ
Tourmaline | Level 20

Like this?

data HAVE;
  input COL1 $16.;
  cards;
notes
name A1
code B1
..
notes
name A2
code B2
;
run;
data WANT;
  set HAVE;
  length NAME CODE  $8;
  retain NAME;
  if COL1=:'name' then NAME=substr(COL1,6);
  if COL1=:'code' then do ;
    CODE=substr(COL1,6);
    output;
    call missing(NAME, CODE);
  end;
run;

 

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
  • 1 reply
  • 1187 views
  • 1 like
  • 2 in conversation