Hi
Consider a Table:
ID Var1 Var2 Var3 Var4 Var5
1 3 3 3 4 4
2 2 2 2 3 3
I would like to see, when is the first time value 3 has generated in var1 - var5
My Method to do it is following:
Data Need;
Set Have;
Array check(*) Var1 - Var5
Do i = 1 to 5;
if Check(i) = 3 then do;
Flag = i; goto : en;
output;
end;
en: Run;
Goto statement helps me come out of the loop first time my condition satisties. It might not be a sophisticated way to write code but it works. Any suggestions how this can be improved or something alternative?
Thanks
Hi "Bhpinder",
basically you are doing the right thing, but yes, it can be improved.
further possibilities for improvement:
Generally I strongly advice to bookmark SAS online documentation. My favourite (not having had access to any SAS system above 9.1.3) being - you guess it - the 9.1.3 Documentation and there especially the Language Reference Dictionary book. SAS has such a rich set of functions, formats, informats, options and statements that skimming through its pages is time well invested. Furthermore there are overview pages in this document such as Functions and CALL Routines : Functions and CALL Routines by Category that I always turn to when a voice inside me says "there must be some function, format, whatsoever that exactly does this".
Kind regards
Robert
Hi "Bhpinder",
basically you are doing the right thing, but yes, it can be improved.
further possibilities for improvement:
Generally I strongly advice to bookmark SAS online documentation. My favourite (not having had access to any SAS system above 9.1.3) being - you guess it - the 9.1.3 Documentation and there especially the Language Reference Dictionary book. SAS has such a rich set of functions, formats, informats, options and statements that skimming through its pages is time well invested. Furthermore there are overview pages in this document such as Functions and CALL Routines : Functions and CALL Routines by Category that I always turn to when a voice inside me says "there must be some function, format, whatsoever that exactly does this".
Kind regards
Robert
The function is WHICHN
Great! Thanks, data _null_,
now that I have access to "my" z/OS system again, I verified that both search type functions (WHICHC/WHICHN) though not documented do work with SAS 9.1.3 as well (z/OS 1.12 here with SAS 9.1.3, &sysvlong displaying - retyped - 9.01.01M3P020206).
Added the 9.2 categorized list of functions to my bookmarks.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.