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

I am creating a table and updating the record with some queries.



%let final_File=F_OUTPUT.DS_daily_demand_F;
%let level= (catx('',OPTION_NUMBER,date,fascia));


data &final_File._checkpoints;
format Checkpoints $30. Total_Count 10. comment $100. Check_Date date9.;
run;


proc sql;

update &final_File._checkpoints as a
set
Checkpoints="Total Records",
Total_Count=(select Count(*) from &final_File.),
comment="This is total number cases here",
Check_Date=today();

 

proc append &final_File._checkpoints=
Checkpoints="Unique record",
Total_Count=(select Count(distinct product_ID) from &final_File.),
comment="This is unique number of cases",
Check_Date=today();


quit;

 

highlighted portion is not working, how should I write this code.

1 ACCEPTED SOLUTION

Accepted Solutions
Srigyan
Quartz | Level 8

 

I have done this in following way...

 

 

proc sql;

update &final_File._checkpoints as a
set
Checkpoints="Total Records",
Total_Count=(select Count(*) from &final_File.),
comment="This is total number cases here",
Update_Date=today();

insert into &final_File._checkpoints
set Checkpoints="Unique record",
Total_Count=(select Count(distinct &level.) from &final_File.),
comment="This is unique number of cases",
Update_Date=today();

quit;

View solution in original post

3 REPLIES 3
noling
SAS Employee

It looks like you're trying to alter your &final_File._checkpoints twice - once in your PROC SQL update, and maybe again in your proc append?

 

If you're updating records use PROC SQL. If you want to stack/add additional records use PROC APPEND with base=<original data set> data=<dataset with new records>. PROC APPEND can't use data step logic like you're trying to do. You can first create a temporary dataset with your new data before appending. See my example here.

 

You should also look at the PROC APPEND syntax, since it looks like you're completely guessing at it, which usually isn't a great approach for SAS.


Register today and join us virtually on June 16!
sasglobalforum.com | #SASGF

View now: on-demand content for SAS users

Srigyan
Quartz | Level 8

 

I have done this in following way...

 

 

proc sql;

update &final_File._checkpoints as a
set
Checkpoints="Total Records",
Total_Count=(select Count(*) from &final_File.),
comment="This is total number cases here",
Update_Date=today();

insert into &final_File._checkpoints
set Checkpoints="Unique record",
Total_Count=(select Count(distinct &level.) from &final_File.),
comment="This is unique number of cases",
Update_Date=today();

quit;

ballardw
Super User

@Srigyan wrote:

I am creating a table and updating the record with some queries.



%let final_File=F_OUTPUT.DS_daily_demand_F;
%let level= (catx('',OPTION_NUMBER,date,fascia));


data &final_File._checkpoints;
format Checkpoints $30. Total_Count 10. comment $100. Check_Date date9.;
run;


proc sql;

update &final_File._checkpoints as a
set
Checkpoints="Total Records",
Total_Count=(select Count(*) from &final_File.),
comment="This is total number cases here",
Check_Date=today();

 

proc append &final_File._checkpoints=
Checkpoints="Unique record",
Total_Count=(select Count(distinct product_ID) from &final_File.),
comment="This is unique number of cases",
Check_Date=today();


quit;

 

highlighted portion is not working, how should I write this code.


I suggest copying the Log output for the code that is not working. Copy from the log, the code and all messages related to the code an paste into a code box opened using the forum's {I} icon to preserve formatting.

 

I am fairly sure you are getting a number of error messages that are actually fairly clear.

 

Also describe what you actually attempting to do with the append code.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1098 views
  • 0 likes
  • 3 in conversation