BookmarkSubscribeRSS Feed
Minku
Fluorite | Level 6

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,

 

5 REPLIES 5
PaigeMiller
Diamond | Level 26
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;
--
Paige Miller
Minku
Fluorite | Level 6
Thank you 😊
bbkkku
Calcite | Level 5
i have a similar issue, but I am not able to solve it. Under each column (for me col1 is week1 of eahc year from 91 to 2021) i have many different values (could be more than a hundred), How do I make a count of each of the different values across all my columns?
ballardw
Super User

@bbkkku 

 

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.

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1880 views
  • 1 like
  • 4 in conversation