I have one dataset like student data
name english science history math
ram 65 48 89 49
Hari 79 69 90 98
gopal 87 35 30 90
I have to create 3 dataset like ram , hari ,gopal
Ram dataset contail like below
english 56
science 48
History 89
hari and gopal dataset are same as ram
Kindly help me .
Thanks,
Regards,
Ashwini
You can use PROC TRANSPOSE to rotate the grades into rows.
Splitting into individual datasets is harder. But we can query the original dataset and generate some code into macro variables to make it a little easier.
Are you sure you need the individual files? Why not just use the single rotated dataset and use a BY statement to process it by NAME?
data have;
input name $ english science history math;
cards;
ram 65 48 89 49
Hari 79 69 90 98
gopal 87 35 30 90
;;;;
proc transpose data=have out=want(rename=(_name_=course col1=grade));
by name notsorted ;
run;
proc sql noprint ;
select 'grade_'||name
, 'if name='||quote(name)||' then output grade_'||name
into :dsnames separated by ' '
, :ifstatement separated by ';'
from have
;
quit;
data &dsnames;
set want ;
&ifstatement ;
run;
Another approach, after one transposes the data, is to use a hash to create the separate files. E.g., I think that the following produces the files you want:
data have;
input name $ english science history math;
cards;
ram 65 48 89 49
Hari 79 69 90 98
gopal 87 35 30 90
;
proc transpose data=have out=temp(rename=(_name_=course col1=grade));
by name notsorted ;
run;
data temp (index = (name));
set temp;
run;
data _null_;
dcl hash hh ( );
hh.definekey ('k' );
hh.definedata ('name','course','grade');
hh.definedone ();
do k = 1 by 1 until (last.name);
set temp;
by name;
hh.add ();
end;
hh.output (dataset: name);
run;
Thanks Tom and Art a lot for your kind information.
Regards,
Ashwini
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.