BookmarkSubscribeRSS Feed
Mdormond
Calcite | Level 5

I've asked this question in a similar manner in a previous post- but I wanted to clarify what I was asking. I currently have about 7 dummy variables all pertaining to psychological outcome (anxiety, stress, multiple personalities, etc) coded as 1=yes and 0=no. I would like to collapse all of these variables into one "psych condition" variable with 1=yes and 0=no. The variable would get a value of 1 if any of the 7 psychological outcomes had a value of 1. I've tried coding it a few different ways, but every time I overwrite the previous value and end up with every observation having a value of zero. Is there an easier way to do this?

3 REPLIES 3
stat_sas
Ammonite | Level 13

data want;

set have;

psychological_outcomes=0;

if anxiety=1 or stress=1 or personalities=1 or var4=1 or var5=1 or var6=1 or var7=1 then psychological_outcomes=1;

run;

data_null__
Jade | Level 19

Make an array of the dummy variables and use whichn

data code;
   array v[3] 8;
  
input (v
  • )(
  • 1.);
       new = not not whichn(1,of v
  • );
  •    cards;
    000
    001
    010
    011
    100
    101
    110
    111
    ;;;;
       run;
    proc print;
      
    run;
    RichardinOz
    Quartz | Level 8

    Data want ;

         Set have ;

         outcome = max (anxiety, stress, multiple, etc1, etc2, etc3, etc4) ;

    Run ;

    Richard

    sas-innovate-2024.png

    Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

    Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

     

    Register now!

    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
    • 3 replies
    • 392 views
    • 0 likes
    • 4 in conversation