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
Diamond | Level 26

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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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