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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1976 views
  • 7 likes
  • 4 in conversation