BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

Dear sir/madam,

 

I just posted a the following question. There are few mistakes in previous one. I am posting again.

 

I am having little trouble in my code . Please help.

 

I am creating a new variable 'AESERN' from the information contained in 7 variables.

 the 7 variables are;

                               AESER    AESDTH      AESLIFE     AESHOSP      AESCONG       AESDISAB      AESMIE        INFECDIS

                                    N                N                 N                    N                N                        N                  N                    N

                                     Y               N                  N                   N                N                         N                 N                     N

                                    Y                N                  N                    N               N                          N                Y                     N

                                    Y                 Y                  Y                     N              N                           N               N                     N

 

SPECS shows: if AESER = 'N' THEN AESERN = 'No';
if AESER = 'Y' THEN AESERN = 'Yes';
if AESDTH OR AESLIFE OR AESHOSP OR AESCONG OR AESDISAB OR AESMIE OR INFECDIS are 'Y' then append " (" to AESERN and then display the number(s) separated by commas "," of the conditions met. Follow all numeric code values with ")".
IF AESDTH = 'Y' THEN APPEND 1.
IF AESLIFE = 'Y' THEN APPEND 2.
IF AESHOSP = 'Y' THEN APPEND 3.
IF AECONG = 'Y' THEN APPEND 5.
IF AESDISAB = 'Y' THEN APPEND 4.
IF AESMIE = 'Y' THEN APPEND 6.
IF INFECDIS = 'Y' THEN APPEND 7.
As an example, if both AESDTH and INFECDIS are marked, then AESERN woul have value "Yes (1,6)".

 

 

My code:

if AESER = 'N' THEN AESERN = 'No';
array AESP {7} AESDTH AESLIFE AESHOSP AESCONG AESDISAB AESMIE INFECDIS;
do i = 1 to 7;
if AESER = 'Y' and array (i) = 'N' then AESERN = 'Yes';
if AESER = 'Y' and array (i) = 'Y' then AESERN = 'Yes'||'('||i||')';
end;

 

This code is not giving me output. Please help. Thanks.

3 REPLIES 3
knveraraju91
Barite | Level 11

Dear sir/madam,

 

I am havinh little trouble in my code . Please help.

 

I am creating a new variable 'AESERN' from the information contained in 7 variables.

 the 7 variables are; AESER    AESDTH      AESLIFE     AESHOSP      AESCONG       AESDISAB      AESMIE        INFECDIS

                                    N                N                 N                    N                N                        N                  N                    N

                                     Y               N                  N                   N                N                         N                 N                     N

                                    Y                N                  N                    N               N                          N                Y                     N

                                    Y                 Y                  Y                     N              N                           N               N                     N

 

SPECS shows: if AESER = 'N' THEN AESERN = 'No';
if AESER = 'Y' THEN AESERN = 'Yes';
if AESDTH OR AESLIFE OR AESHOSP OR AESCONG OR AESDISAB OR AESMIE OR INFECDIS are 'Y' then append " (" to AESERN and then display the number(s) separated by commas "," of the conditions met. Follow all numeric code values with ")".
IF AESDTH = 'Y' THEN APPEND 1.
IF AESLIFE = 'Y' THEN APPEND 2.
IF AESHOSP = 'Y' THEN APPEND 3.
IF AECONG = 'Y' THEN APPEND 5.
IF AESDISAB = 'Y' THEN APPEND 4.
IF AESMIE = 'Y' THEN APPEND 6.
IF INFECDIS = 'Y' THEN APPEND 7.
As an example, if both AESDTH and INFECDIS are marked, then AESERN woul have value "Yes (1,6)".

 

 

My code:

if AESER = 'N' THEN AESERN = 'No';
array AESP {7} AESDTH AESLIFE AESHOSP AESCONG AESDISAB AESMIE INFECDIS;
do i = 1 to 7;
if AESER = 'Y' and array (i) = 'N' then AESERN = 'Yes';
if AESER = 'Y' and array (i) = 'Y' then AESERN = 'Yes'||'('||i||')';

 

This code giving me output. Please help. Thanks.
end;

ballardw
Super User

You should provide more example of what the outpu should look like. Also, how will you use that AESERN variable?

 

You may very well have problems if your variable AESERN already exists as the existing length for AESERN will limit what you may get for a result with the concatenation of values. If it doesn't exist you need to assign a value long enough all of the characters you expect.

 

You are also referencing the array incorrectly ;

if AESER = 'Y' and array (i) = 'N' then AESERN = 'Yes';

should be

if AESER = 'Y' and AESP (i) = 'N' then AESERN = 'Yes';

 

with your requirement to wrap those i values within () you will need a bit more logic


data want;
   set have;
   length aesern $ 25 tstr $ 15;
   if AESER = 'N' THEN AESERN = 'No';
   array AESP {7} AESDTH AESLIFE AESHOSP AESCONG AESDISAB AESMIE INFECDIS;
   do i = 1 to 7;
      if AESER = 'Y' and AESP (i) = 'N' then tstr=catx(',',tstr,i);
   end;
   /* you only need to assing the YES part if any were found before*/
   if lengthn (tstr)>0 then Aesern= catt('Yes (',tstr,')');
   drop tstr;
run;
ballardw
Super User

Please do not create duplicate posts, especially in the same section of the forum. If you need to change something you can edit your post. Multiple posts get confusing as parts of answers, or your responses for details end up in different threads and the final result may not be cohesive.

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
  • 883 views
  • 0 likes
  • 2 in conversation