The SAS Output Delivery System and reporting techniques

how to write the input to next line when missing value is found

Accepted Solution Solved
Reply
Contributor
Posts: 32
Accepted Solution

how to write the input to next line when missing value is found

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.


Accepted Solutions
Solution
‎03-14-2012 11:04 AM
Super User
Posts: 5,092

how to write the input to next line when missing value is found

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


All Replies
SAS Super FREQ
Posts: 8,743

how to write the input to next line when missing value is found

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

Solution
‎03-14-2012 11:04 AM
Super User
Posts: 5,092

how to write the input to next line when missing value is found

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.

Respected Advisor
Posts: 3,124

Re: how to write the input to next line when missing value is found

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

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 201 views
  • 0 likes
  • 4 in conversation