Hey Guys,
I am trying to change the output of my rawdata file. In the rawdata, the output is in the following format
Name Test1 Test2 Test3 Test4
xyz 45 78 88 100
avb -1 89 76 29
But I want to change it to following format
Name Score
xyz 45
xyz 78
xyz 88
xyz 100
xyz 89 (skip -1 cuz it's less than0)
I am trying to use array and output statement but having trouble.
Can someone help?
P.S. I uploaded a pic not sure if it worked.
Best,
LB
I don't have a SAS program to use right now but try something like this:
data try;
set yourdata; ******************** change the dataset name here;
array Tests[4] Test1-Test4;
do i =1 to 4;
if Tests(i) >=0 then do; **** this should exclude values with less than 0;
Score=Tests(i);
output;
end;
end;
keep name score;
run;
Thank you very much. It worked.
LB
Hey Arrogant,
Can I ask for little more help?
Following is my code for my hw.
I am trying to create a new variable called Grade as Pass or Fail but for some reason it is not working. Any idea how I can fix it?
dm "out;clear;log;clear";
option pageno=1;
title "Test Record";
%let path = C:\SAS\Hw 5;
libname sasdata "&path";
filename rawdata "&path\Testrecords.txt";
data work.records1;
Infile rawdata lrecl=100 pad;
Input ID Name $ Gender $ Height Weight DOB$ Test1 Test2 Test3 Test4 Test5 Test6 ;
run;
data records2;
set records1;
Array Test(*) Test1 Test2 Test3 Test4 Test5 Test6;
do i = 1 to 6;
If Test(i) gt -1 then do;
Score = test(i);
output;
end;
end;
Drop ID Gender Height Weight DOB i Test1 - Test6 ;
run;
proc contents;
run;
proc summary data = records2 nway missing;
class Name;
var Score;
output out = Score mean=;
run;
proc format;
value Grade
0 -< 70 = 'Fail'
70 - High = 'Pass'
run;
proc print;
format Score Grade.;
run;
oops sorry didn't see the message earlier. Guess it's too late for your homework.
If you're just replacing the "Score" with the format you've create "Pass" or "Fail" then it should work fine. If you want to create a new variable called "Grade" and display as "pass" or "fail" after Score variable, then you'll have to create a new variable. Format will only replace the existing "score" variable. To create a new variable with the condition you can use "if then" statement.
Also, you have a missing semicolon in the proc format statement before run statement.
good luck.
Last edited: 03-Apr-15 10:03 AM
Please log in to reply to this post
You can also log in using your Facebook
What people are reading
You might like these other discussions...
· Posts 3
· Viewed 187
· Likes 1