Hi Everyone,
I have a "have" file and it should have say 4 rows.
I want to create a error file if the "have" file has less than 4row.
So in practice, when I see that error file, I know the issue.
Can anyone help me with that?
Thank you so much.
HHC
data have;
input var;
datalines;
1
2
3
;run;
data have;
input Jan1 _1_jan Feb March_ ;
datalines;
1 0 0 0
2 1 1 1
;run;
data _null_;
call symput('nobs',put(x,best.));
set have nobs=x;
stop;
run;
%macro errout;
%if &nobs le 4 %then %do;
data have;
set have;
notice= "not enough observations";
run;
%end;
%mend;
%errout;
@hhchenfx wrote:
When I run your code, I receive this notice:
ERROR: Insufficient authorization to access C:\Program Files\SASHome\SASFoundation\9.3\errorout.
NOTE: The SAS System stopped processing this step because of errors.
I am using my computer and I am using Admin account.
Not sure why it is like that.
Thank you,
My filename was of course just a placeholder; use a name with an absolute path that points to a location where you have write permission.
You can retrieve the number of observations in a dataset from sashelp.vtable or dictionary.tables (the latter with proc sql).
Or you can run a data step:
data _null_;
call symput('nobs',put(x,best.));
set have nobs=x;
stop;
run;
Then you can use that in a macro:
%macro errout;
%if &nobs le 4 %then %do;
data _null_;
file "errorout";
put "not enough observations";
run;
%end;
%mend;
%errout
When I run your code, I receive this notice:
ERROR: Insufficient authorization to access C:\Program Files\SASHome\SASFoundation\9.3\errorout.
NOTE: The SAS System stopped processing this step because of errors.
I am using my computer and I am using Admin account.
Not sure why it is like that.
Thank you,
HC
@hhchenfx wrote:
When I run your code, I receive this notice:
ERROR: Insufficient authorization to access C:\Program Files\SASHome\SASFoundation\9.3\errorout.
NOTE: The SAS System stopped processing this step because of errors.
I am using my computer and I am using Admin account.
Not sure why it is like that.
Thank you,
My filename was of course just a placeholder; use a name with an absolute path that points to a location where you have write permission.
I think this is a good problem to wrap it all up in a macro using PROC SQL:
%macro test(lib=,dsn=,size=);
%local dsn size lib;
proc sql noprint;
select nobs into :nrecs from dictionary.tables
where libname="%upcase(&lib)" and memname="%upcase(&DSN)";
%if &nrecs < &size %then create table error as select * from &lib..&dsn;;
quit;
%mend;
%test(lib=sashelp,dsn=class,size=20);
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.