BookmarkSubscribeRSS Feed
sasboy007
Calcite | Level 5

Hi all,

I'm appending data to an already created table.  I'm using proc sql below to bring back the highest ID value so that I can start my new counter where it left off.  My code is below but I'm running into some issues with my IF statment at the very bottom.  I don't think the counter is actually incrementing from the last database position.  Any insight is appreciated.

/*this brings back the highest numID*/
proc sql noprint;
   select max(numID)
      into :counter 
      from gate.randomTable;

quit;

data work.newData
mycounter=0;

(keep =
mycounter
x

);

retain
mycounter
x

;

set work.dataY;

if first.x then mycounter=&counter;

      mycounter + 1;

   run;

4 REPLIES 4
data_null__
Jade | Level 19

don't you need

BY X;

RW9
Diamond | Level 26 RW9
Diamond | Level 26

You could also do it:

proc sql;

  create table TAB1 as

  select  MODEL,

          MONOTONIC() as NUMID

  from    SASHELP.CARS;

  create table TAB2 as

  select  MODEL,

          NUMID

  from    TAB1

  union all

  select  MODEL,

          MONOTONIC() + (select max(NUMID) from TAB1) as NUMID

  from    TAB1;

quit;

charley_sas
SAS Employee

I'm not sure where X comes from so I removed the references to it.  Try the following:

data work.newData

retain mycounter &counter;

set work.dataY;

mycounter + 1;

<other code goes here>;

run;

sasboy007
Calcite | Level 5

Hey thanks.  I completely forgot to add &counter to my RETAIN  statement.

I ended up using and it seems to work now.

mycounter=&counter;

mycounter+1;

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
  • 928 views
  • 3 likes
  • 4 in conversation