BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

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

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

4 REPLIES 4
Kurt_Bremser
Super User

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.

Scott_Mitchell
Quartz | Level 8

Thanks everyone.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

Keith
Obsidian | Level 7

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;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 4 replies
  • 2484 views
  • 7 likes
  • 4 in conversation