Hello team,
I have inherited a code that I run on a monthly basis.
data mydata;
set mydata1 where (keep this that datatime where=(datepart(datetime) >= "01012021"
mydata2 (keep=datetime fileNum);
cnt = 1;
date1 = datepart(datetime);
datemount = put(date1, yymmn6.);
if datemount > "202201" then output;
run;
proc summary nway missing data =mydata;
var cnt;
........
run;
on the first statement? Does cnt becomes 1 when the first time SAS reads the first record and then it becomes 2 on the second row since SAS reads sequentially.
What is the value of cnt on the second statement? Is it incremented?
Can anyone please kindly explain it to me?
Regards,
BlueBerry
What is the value of cnt in the statement?
Since the code sets CNT to one on every observations that means the variable cnt will have one on every observation.
But another way to interpret that questions is
What value does the CNT variable add to this code
It kind of depends on what you are using PROC SUMMARY to do in that last step. But it does not look like it is adding any value. Let's do a simple test using SASHELP.CLASS.
proc summary data=sashelp.class;
output out=want;
run;
proc print data=want;
run;
data class;
set sashelp.class;
cnt=1;
run;
proc summary data=class;
var cnt;
output out=want;
run;
proc print data=want;
run;
The only useful statistic is the count of observations that the _FREQ_ variable already provided.
Your code won't run anyway because of syntax errors:
set mydata1 where (keep this that datatime where=(datepart(datetime) >= "01012021"
mydata2 (keep=datetime fileNum);
You have four opening, but only two closing brackets.
Do you really want to include a dataset named "WHERE"?
The result of DATEPART is a number, so comparing it to a string won't work.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.