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

Hi,

My dataset is like this,

id  record1-record4

1 23 . . .

2 24 34 45 46

3 65 76 . .

4 42 . . .

I want O/p as follows,

id  record

1 23

2 24

2 34

2 45

2 46

3 65

3 76

4 42

Any one help me in achieving this please.

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

If your objective is to re-shape an existing SAS data set, here's one way:

data new;

   set old;

   array all4 {4} record1-record4;

   do _n_=1 to 4;

      if all4{_n_} > . then do;

         record = all4{_n_};

         output;

     end;

   end;

   keep id record;

run;

If you have some other objective in mind, just let us know.

View solution in original post

3 REPLIES 3
Cynthia_sas
SAS Super FREQ

Hi:

  You do not say what your required output is:

1) a data set?

2) a report?

3) if a report, what is your destination of choice? (HTML, RTF, PDF, etc)

Since you are posting this to the ODS and Reporting forum, I figure you must want a report, especially since your asks about "writing" to a new line -- which suggests a report.

You could accomplish a report with a DATA step program, but it would probably be much easier to use a PROC TRANSPOSE to rotate your dataset from "wide" to "long" and then just use PROC PRINT to print the new structure.

cynthia

Astounding
PROC Star

If your objective is to re-shape an existing SAS data set, here's one way:

data new;

   set old;

   array all4 {4} record1-record4;

   do _n_=1 to 4;

      if all4{_n_} > . then do;

         record = all4{_n_};

         output;

     end;

   end;

   keep id record;

run;

If you have some other objective in mind, just let us know.

Haikuo
Onyx | Level 15

FWIW:

data _null_;

  if _n_=1 then do;

     dcl hash h(multidata:'y', ordered:'a');

h.definekey('id');

h.definedata('id','record');

h.definedone();

   end;

   set have end=done;

      array r record1-record4;

do over r;

record=r;

if not missing (r) then rc=h.add();

end;

  if (done) then h.output(dataset: 'want');

  run;

Regards,

Haikuo

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
  • 3 replies
  • 837 views
  • 0 likes
  • 4 in conversation