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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.