- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
…then do;
Output;
Cnt + 1;
End;
The top condition would make more sense with cnt = 0, or the counter will show one more observation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.