ARRAY SCD(*) SC001-SC500;
DO IS = 1 TO 500;
IF SUBSTR(SCD(IS),1,1) > "V" THEN I = 500;
ELSE
IF SUBSTR(SCD(IS),1,1) = '*' THEN
DO;
SUBSTR(TRIM,1,2) = SUBSTR(SCD(IS),2,2);
TRIM1 = SUBSTR(SCD(IS),1,3);
END;
ELSE
IF SUBSTR(SCD(IS),1,1) = '-' THEN
DO;
SUBSTR(TRIM,3,2) = SUBSTR(SCD(IS),2,2);
TRIM2 = SUBSTR(SCD(IS),1,3);
END;
a) don't write program code in all capitals
b) what's your doubt?
do you have doubt in below statement:
SUBSTR(TRIM,1,2) = SUBSTR(SCD(IS),2,2);
If yes, here, TRIM is a variable and you are replacing its first 2 bytes from he SCD array
What is the question here? Post eaxmple test data, in the form of a datastep, and what you expect the output to be so that we can see what the process is. Avoid coding in capitals as this makes code very hard to read. Use the code blocks - it is a {I} above where you post, which moves code to a proper editor area. It looks to me like you could simplfy your if branching down to one select:
do is=1 to 500; select; when (substr(scd(is),1,1) > "V") i=500; when ...; end; end;
Do note, I would advise not doing the substr(scd(is),1,1) > "V", that isn't what I would call logical approach. V is a character, it works as it also has an associated ASCII code, which is what you are comparing there, but that doesn't mean that "x" would be > "V" for instance. I would say,
upcase(substr(scd(is),1,1)) in ("W","X","Y","Z")
would be a clearer way of writing it.
Edit: One other thing to add. It always jumps out at me when someone states they have > 50 variables in a dataset. My first question would always be why? There are some instances of course where it is easier, and sometimes necessary to do it this way, however I find that most times many variables makes hard work. It may be that your logic can be simplified merely by restructuring your data into a normalised form.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.