Skip to content

Commit

Permalink
bulk upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiangtang committed Jun 19, 2014
1 parent fff424a commit cb397d3
Show file tree
Hide file tree
Showing 33 changed files with 8,175 additions and 0 deletions.
49 changes: 49 additions & 0 deletions IO/NOBS/MTCNTOBS.sas
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
%macro MTCNTOBS(data=_last_);
%* This macro returns the number of observations in a data set,
or . if the data set does not exist or cannot be opened.
- It first opens the data set. An error message is returned
and processing stops if the dataset cannot be opened.
- It next checks the values of the data set attributes
ANOBS (does SAS know how many observations there are?) and
WHSTMT (is a where statement in effect?).
- If SAS knows the number of observations and there is no
where clause, the value of the data set attribute NLOBS
(number of logical observations) is returned.
- If SAS does not know the number of observations (perhaps
this is a view or transport data set) or if a where clause
is in effect, the macro iterates through the data set
in order to count the number of observations.
The value returned is a whole number if the data set exists,
or a period (the default missing value) if the data set
cannot be opened.
This macro requires the data set information functions,
which are available in SAS version 6.09 and greater. ;
%* By Jack Hamilton, First Health, January 2001. ;
%local dsid anobs whstmt counted rc;
%let DSID = %sysfunc(open(&DATA., IS));
%if &DSID = 0 %then
%do;
%put %sysfunc(sysmsg());
%let counted = .;
%goto mexit;
%end;
%else
%do;
%let anobs = %sysfunc(attrn(&DSID, ANOBS));
%let whstmt = %sysfunc(attrn(&DSID, WHSTMT));
%end;
%if &anobs=1& &whstmt = 0 %then
%let counted = %sysfunc(attrn(&DSID, NLOBS));
%else
%do;
%if %sysfunc(getoption(msglevel)) = I %then
%put INFO: Observations in "&DATA." must be counted by iteration.;
%let counted = 0;
%do %while (%sysfunc(fetch(&DSID)) = 0);
%let counted = %eval(&counted. + 1);
%end;
%end;
%let rc = %sysfunc(close(&DSID));
%MEXIT:
&COUNTED.
%mend MTCNTOBS;
64 changes: 64 additions & 0 deletions IO/NOBS/anyobs.sas
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*******************************************************************************
Program :
Parameters :
SAS Version: 9.2
Purpose :
Developer :
Modified :
Notes :
*******************************************************************************/

%macro anyobs(data);
%*http://www2.sas.com/proceedings/sugi26/p095-26.pdf;
%* This macro returns 1 if there are any observations in a data set,
0 if the data set is empty, or . if the data set does not exist or
cannot be opened.
- The macro first opens the data set. An error message is displayed
and processing stops if the dataset cannot be opened.
- It next checks the values of the data set attributes
ANOBS (does SAS know how many observations there are?) and
WHSTMT (is a where statement in effect?).
- If SAS knows the number of observations and there is no
where clause, the data set attribute ANY is used to determine
whether there are any observations.
- If SAS does not know the number of observations (a view or transport
data set) or if a where clause is in effect, the macro tries to read
the first observation. If a record is found, the macro returns 1,
otherwise it returns 0.
This macro requires the data set information functions,
which are available in SAS version 6.09 and greater. ;
%* By Jack Hamilton, First Health, January 2001. ;
%local dsid anobs whstmt hasobs rc;
%let DSID = %sysfunc(open(&DATA., IS));
%if &DSID = 0 %then
%do;
%put %sysfunc(sysmsg());
%let hasobs = .;
%goto mexit;
%end;
%else
%do;
%let anobs = %sysfunc(attrn(&DSID, ANOBS));
%let whstmt = %sysfunc(attrn(&DSID, WHSTMT));
%end;
%if &anobs=1& &whstmt = 0 %then
%do;
%let hasobs = %sysfunc(attrn(&DSID, ANY));
%if &hasobs = -1 %then
%let hasobs = 0;
%end;
%else
%do;
%if %sysfunc(getoption(msglevel)) = I %then
%put INFO: First observation in "&DATA." must be fetched.;
%let hasobs = 0;
%if %sysfunc(fetch(&DSID)) = 0 %then
%let hasobs = 1;
%end;
%let rc = %sysfunc(close(&DSID));
%MEXIT:
&HASOBS.
%mend anyobs;

50 changes: 50 additions & 0 deletions IO/NOBS/mtanyobs.sas
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
%macro mtanyobs(data=_last_);
%* This macro returns 1 if there are any observations in a data set,
0 if the data set is empty, or . if the data set does not exist or
cannot be opened.
- The macro first opens the data set. An error message is displayed
and processing stops if the dataset cannot be opened.
- It next checks the values of the data set attributes
ANOBS (does SAS know how many observations there are?) and
WHSTMT (is a where statement in effect?).
- If SAS knows the number of observations and there is no
where clause, the data set attribute ANY is used to determine
whether there are any observations.
- If SAS does not know the number of observations (a view or transport
data set) or if a where clause is in effect, the macro tries to read
the first observation. If a record is found, the macro returns 1,
otherwise it returns 0.
This macro requires the data set information functions,
which are available in SAS version 6.09 and greater. ;
%* By Jack Hamilton, First Health, January 2001. ;
%local dsid anobs whstmt hasobs rc;
%let DSID = %sysfunc(open(&DATA., IS));
%if &DSID = 0 %then
%do;
%put %sysfunc(sysmsg());
%let hasobs = .;
%goto mexit;
%end;
%else
%do;
%let anobs = %sysfunc(attrn(&DSID, ANOBS));
%let whstmt = %sysfunc(attrn(&DSID, WHSTMT));
%end;
%if &anobs=1& &whstmt = 0 %then
%do;
%let hasobs = %sysfunc(attrn(&DSID, ANY));
%if &hasobs = -1 %then
%let hasobs = 0;
%end;
%else
%do;
%if %sysfunc(getoption(msglevel)) = I %then
%put INFO: First observation in "&DATA." must be fetched.;
%let hasobs = 0;
%if %sysfunc(fetch(&DSID)) = 0 %then
%let hasobs = 1;
%end;
%let rc = %sysfunc(close(&DSID));
%MEXIT:
&HASOBS.
%mend mtanyobs;
14 changes: 14 additions & 0 deletions IO/NOBS/nobs.sas
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
%macro nobs(ds);
%put >>>>> Running &SYSMACRONAME;
%local nobs;
%let dset=&ds;

%let dsid = %sysfunc(open(&dset));
%if &dsid %then %do;
%let nobs =%sysfunc(attrn(&dsid,nobs));
%let nvars=%sysfunc(attrn(&dsid,nvars));
%let rc = %sysfunc(close(&dsid));
%end;
%else %put ERROR: open for data set &dset failed - %sysfunc(sysmsg());
&nobs;
%mend nobs;
17 changes: 17 additions & 0 deletions IO/NOBS/obsnvars.sas
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

/**********************************************/
/* To compute if no observation in dataset ds */
/*http://support.sas.com/kb/24/671.html*/
/**********************************************/
%macro obsnvars(ds);
%global nobs;
%let dset=&ds;
%let dsid = %sysfunc(open(&dset));
%if &dsid %then
%do;
%let nobs =%sysfunc(attrn(&dsid,NOBS));
%let rc = %sysfunc(close(&dsid));
%end;
%else
%put Open for data set &dset failed - %sysfunc(sysmsg());
%mend obsnvars;
File renamed without changes.
File renamed without changes.
28 changes: 28 additions & 0 deletions IO/Reading All External Files.sas
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
%macro readraw(dir=.);
%local fileref rc did dnum dmem memname;
%let fileref=thisdir;
%let rc=%sysfunc(filename(fileref,&dir));
%let did=%sysfunc(dopen(&fileref));
%let dnum=%sysfunc(dnum(&did));
%do dmem=1 %to &dnum;
%let memname=%sysfunc(dread(&did,&dmem));
%if %upcase(%scan(&memname,-1,.)) = DAT %then
%do;
%let dataset=%scan(&memname,1,.);
data &dataset;
infile "&dir\&memname";
input Course_Code $4. Location $15.
Begin_Date date9. Teacher $25.
;
format Begin_Date date9.;
run;
proc print data=&dataset;
title "%trim(&syslast)";
run;
%end;
%end;
%let rc=%sysfunc(dclose(&did));
%let rc=%sysfunc(filename(fileref));
%mend readraw;
options mprint;
%readraw(dir=C:\Users\Public\Documents\sas\webLiveCourse\1-Base\2Macro\amacr-SAS Macro Programming Advanced Topics-2006)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions IO/_is.sas
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
%macro _is(dir);
%local filrf VarList;
%let rc=%sysfunc(filename(filrf,&dir));
%let did=%sysfunc(dopen(&filrf));
%let dcnt=%sysfunc(dnum(&did));

%do i = 1 %to &dcnt;
%let VarList = &VarList %sysfunc(dread(&did,&i));
%end;

%let rc=%sysfunc(dclose(&did));
&VarList
%mend _is;

%put %_is(c:\);
Loading

0 comments on commit cb397d3

Please sign in to comment.