BookmarkSubscribeRSS Feed
Mayohnim
SAS Employee

I would like to do infinity loop like in JAVA

 

for(i=1;i<200;I++){


       if (COL(i) != COL1 AND COL(i) != "  ") {

                 q_person_type = "Multiple";

       }

       else {

                q_person_type = COL1

        }                

}

 

For SAS Code

 

data test3(keep=q_full_nm q_person_type rename=(q_full_nm=node_tooltip));
    set test2;
    do i = 1 to n by 1;
       q_person_type=COL1;
       if COLi ne ' ' AND COLi ne COL1 then q_person_type="Multiple";
run;

 

I cannot run this code, could you please check it which part i'm wrong

what i want is if COL2, COL3 ... until COL N is not equal to COL1 return "Multiple" but if COL2, COL3 .... until COL N is equal to COL1 or is "  " return COL1

 

Please see picture for more understanding


pic.JPG
3 REPLIES 3
LinusH
Tourmaline | Level 20
You need to fill an array with your col2 to coln variables, and loop over that.
Data never sleeps
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

 

You can use arrays to loop over data, example below.  Please note this code is not tested.  If you want working code, please post test data - in the form of a datastep, which reflects your actual data - and what you want the output to look like.

data want;
  set have;
  array col{3};
  result="Pass";
  do i=2 to 3;
    if col{i} ne col{1} then result="Fail";
  end;
run;
data_null__
Jade | Level 19

I looked at the picture of your data and wrote this.  Perhaps with this and if you provide and explanation of what you need someone will be able to help.

data col;
   infile cards missover;
   input id:$3. (col1-col3)(:$2.);
   cards;
001 TP
002 TP 
003 RP
004 TP
005 TP
006 RP TP
007 RP
008 RP TP
009 RP
010 RP
011 TP RP RP
;;;;
   run;
proc print;
   run;

Capture.PNG

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1231 views
  • 0 likes
  • 4 in conversation