Hi Guys,
I am sure there is a very good reason for this, but I can't seem to get it through my thick head at 2am.
Why, when I run the below code, am I retaining the value of the previous OBS when I concatenate using the 3 arguments below?
DATA ENROLLMENT;
ATTRIB GROUP_ID LENGTH = $400;
DO ID = 1 TO 10;
DO J = 1 TO 1;
GROUP_ID = CATS(GROUP_ID,ID,"P");
END;
OUTPUT;
END;
RUN;
It is driving me nuts. Sorry to ask such a newbie question.
Regards,
Scott
The data step variables are set to missing only when the complete data step enters its next iteration (think of the jump from "run" to "data"). Between "data" and "run" (or whatever begins the next SAS program step) the variables keep their values, no matter how many SET or OUTPUT statements you have.
The data step variables are set to missing only when the complete data step enters its next iteration (think of the jump from "run" to "data"). Between "data" and "run" (or whatever begins the next SAS program step) the variables keep their values, no matter how many SET or OUTPUT statements you have.
Thanks everyone.
Yep, it looks like the last value is being held over in memory after the output statement. Pop a clean statement in after the output, would need to check the documentation as to exactly what it is doing:
DATA ENROLLMENT;
ATTRIB GROUP_ID LENGTH = $400;
DO ID = 1 TO 10;
DO J = 1 TO 1;
GROUP_ID = CATs(GROUP_ID,ID,"P");
output;
group_id="";
END;
END;
RUN;
I believe you can also get around this by using the CALL CATS function.
DATA ENROLLMENT;
ATTRIB GROUP_ID LENGTH = $400;
DO ID = 1 TO 10;
DO J = 1 TO 1;
CALL CATS(GROUP_ID,ID,"P");
END;
OUTPUT;
END;
RUN;
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.