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.
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.
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
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.
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
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.