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