BookmarkSubscribeRSS Feed
BY2
Obsidian | Level 7 BY2
Obsidian | Level 7
NO AAA AAA_L1 AAA_L2 AAA_L3 BBB BBB_L1 BBB_L2 BBB_L3 AAA_I BBB_I
1 0.1         -0.1     1 1
2   -0.1         0.1   0 0
3     -1   -0.1       0 1

 

data want;

set test;

if AAA > 0 OR AAA_L1>0 OR AAA_L2>0 OR AAA_L3>0 THEN AAA_I = 1;ELSE AAA_I = 0;

If BBB < 0 OR BBB_L1<0 OR BBB_L2<0 OR BBB_L3<0 THEN BBB_I = 0;ELSE BBB_I = 1;

run;

Is there any way that could cut short the code as i have more than 50 similar variables as shown above. 

 

Thank you for your help. 

 

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

Try this

 

data have;
infile datalines dlm=',' dsd;
input NO AAA AAA_L1 AAA_L2 AAA_L3 BBB BBB_L1 BBB_L2 BBB_L3;
datalines;
1,0.1,,,,,-0.1,,
2,,-0.1,,,,,0.1,
3,,,-1,,-0.1,,,
;

data want;
   set have;
   array a {*} a:;
   array b {*} b:;
   AAA_I = max(of a[*]) gt 0;
   BBB_I = min(of b[*]) lt 0;
run;
BY2
Obsidian | Level 7 BY2
Obsidian | Level 7

Is it possible to use OR instead of Max for the array? 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 589 views
  • 2 likes
  • 3 in conversation