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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.