Hi All,
I have a dataset like below . For this , I want to create a new variable called 'Total' in this I want to sum the
values only 'Correct ' and 'Yes' from Col1-Col6 horizontally by each subjid , visit and drug wise .Please respond , if you know how to perform this operation ?
subjid visit drug col1 col2 col3 col4 col5 col6 Total
101 1 A Correct Yes Incorrect Correct Correct No 4
101 1 A Incorrect Yes Correct No Correct 3
101 1 B Correct No Correct Correct Yes Correct 5
101 1 B Correct Yes Correct Yes Incorrect 4
101 2 A Correct Yes Incorrect Correct Yes Correct 5
101 2 A Incorrect Yes Correct Correct No Correct 4
101 2 B Correct No Correct Correct Yes Correct 5
101 2 B Correct Yes Correct Yes Incorrect 4
Thanks in advance,
data want;
set have;
array c col1-col6;
total=0;
do i=1 to 6;
if c(i)='Correct' or c(i)='Yes' then total=total+1;
end;
drop i;
run;
You should start your own thread. As author of a thread you have some advantages and responses do not get confused with the requirements of the original poster of this thread.
Provide a small example of data in the form of a data step and what you expect as a result for that example. Or reference one of the SAS supplied example data sets in the SASHELP library like the Sashelp.class data set. That set is very small and easy to make manual example output by examination if needed.
One question to answer is are you expecting the result in a data set or a report that people will read?
Proc freq might be the answer as you would be counting. "Sum" only applies to numeric variables.
Do you have a SAS data set? The text you are using: " Under each column (for me col1 is week1 of eahc year from 91 to 2021) i have many different values" makes it sound like you are thinking of a spreadsheet and SAS works a bit differently.
Hello, @bbkkku
Please start a new thread on this, and also provide an example of the data you war working with (you can just show us a few columns, we don't need to see all of them) and some example of the desired output.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.