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;
don't you need
BY X;
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;
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;
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;
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.
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.