Hi,
I think it can be solved by using proc transpose but not sure. Any ideas are welcome. Many thanks!
Now I have from CSV,
Class | Student | Phy | Che | Phy | Che | Phy | Che |
A | 1 | 95 | 95 | ||||
A | 2 | 85 | 90 | ||||
A | 3 | 80 | 80 | ||||
B | 1 | 88 | 86 | ||||
B | 2 | 95 | 100 |
And what I want is,
Class | Student | Phy | Che |
A | 1 | 95 | 95 |
A | 2 | 85 | 90 |
A | 3 | 80 | 80 |
B | 1 | 88 | 86 |
B | 2 | 95 | 100 |
I guess first of all, we need to deal with the same-name column issue.
Thanks again for any suggestion!
HI @jordenlam Plz try replicating this
data extract;
infile 'your_file' dsd truncover;
input Class $ student @;
do _n_=1 to 3;
input phy che @ ;
if not missing(phy) and not missing(che) then output;
end;
run;
The loop can also be written as
do until(not missing(phy) and not missing(che)) ;
input phy che @ ;
if not missing(phy) and not missing(che) then output;
end;
This can be handled immediately when reading the csv file. Please post a few example lines of the csv file, using the {i} button.
Thanks!
This is the data from CSV,
Class Student Phy Che Phy Che Phy Che A 1 95 95 A 2 85 90 A 3 80 80 B 1 88 86 B 2 95 100
HI @jordenlam Plz try replicating this
data extract;
infile 'your_file' dsd truncover;
input Class $ student @;
do _n_=1 to 3;
input phy che @ ;
if not missing(phy) and not missing(che) then output;
end;
run;
The loop can also be written as
do until(not missing(phy) and not missing(che)) ;
input phy che @ ;
if not missing(phy) and not missing(che) then output;
end;
There's no delimiter in there, so it's not a csv file.
Did you transpose the e and s in qusetion ? 🙂
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.