/**********************************************************************/ /**********************************************************************/ /* Example 2 */ /* EXMPL002.SCL - Test data set for existence, # of observations. */ INIT: /* Test to see if SCLDEMO.BASEBALL exists. */ rc=libname('SCLDEMO','C:\SCLDEMO'); baseball_exist=exist('SCLDEMO.BASEBALL'); /* If SCLDEMO.BASEBALL exists, get the number of observations. */ if baseball_exist then do; ds_id=open('SCLDEMO.BASEBALL','IS'); nobs=attrn(ds_id,'NOBS'); put 'Number of observations in SCLDEMO.BASEBALL= 'nobs; rc=close(ds_id); end; /* Next line suppresses compiler warning that rc is not used. */ rc=rc; return; /**********************************************************************/ /* Example 3 */ /* EXMPL003.SCL - Send the root subdirectory list to an SLIST */ /* entry. */ INIT: /* Make temporary directory nodes list. */ tmp_lst=makelist(); /* Open root directory to make list. */ rc=filename('CURNODE','C:\'); dir_id=dopen('CURNODE'); if dir_id lt 1 then do; put 'Directory Open Failed'; msg=sysmsg(); put msg; return; end; /* Get directory entries. */ mbr_cnt=dnum(dir_id); do i=1 to mbr_cnt; mbr_nm=dread(dir_id,i); rc=insertc(tmp_lst,mbr_nm,-1); end; rc=filename('CURNODE',''); /* De-assign fileref. */ call putlist(tmp_lst,'List of all Root Directory Members',1); /* Test directory entries to see if valid subdirectories. */ dir_lst=makelist(); mbr_cnt=listlen(tmp_lst); do i=1 to mbr_cnt; dir_nm=getitemc(tmp_lst,i); tst_pth='C:\'||dir_nm; rc=filename('TSTNODE',tst_pth); tst_id=dopen('TSTNODE'); if tst_id then do; rc=insertc(dir_lst,dir_nm,-1); rc=dclose(tst_id); end; rc=filename('TSTNODE',''); end; rc=dclose(dir_id); rc=dellist(tmp_lst); call putlist(dir_lst,'List of Valid Subdirectories',1); /* Save directory list to an SLIST entry. */ dummylst=0; /* Dummy attributes list id. */ rc=savelist('catalog', 'SCLDEMO.MYPGMS.EXMPL003.SLIST', dir_lst, dummylst, 'List of Root Subdirectories'); rc=dellist(dir_lst); rc=rc; return; /**********************************************************************/ /* Example 4 */ /* EXMPL004.SCL - List statistics for pair of baseball teams. */ INIT: /* Must use variables prior to FETCH in order to work. */ team1=''; team2=''; /* Read selected teams from SAS data set. */ dsid=open('SCLDEMO.SLCTTEAM','IS'); call set(dsid); rc=fetch(dsid); rc=close(dsid); /* Make sure that indentation is preserved with SUBMIT block. */ control asis; /* Print only the observations for the selected teams. */ submit continue; proc print data=scldemo.baseball; where team in('&team1','&team2'); run; endsubmit; rc=rc; return; /**********************************************************************/ /* Example 5 */ /* EXMPL005.SCL - Print to a remote printer based upon user id. */ INIT: /* Create the look-up SCL list. */ prt_id_lst=makelist(); rc=insertc(prt_id_lst,'PT0001',-1,'USER101'); rc=insertc(prt_id_lst,'PT0005',-1,'USER102'); rc=insertc(prt_id_lst,'PT0006',-1,'USER103'); /* Select printer. */ user_id=symget('SYSUID'); list_position=nameditem(prt_id_lst,user_id); if list_position then slctd_prt=getitemc(prt_id_lst,list_position); else do; put 'Unknown User Selected'; return; end; /* Create the PRINTOFF command. */ x_cmd='PRINTOFF (MYPRINT) CLASS(A) DEST('||slctd_prt||')'; /* Issue PRINTOFF command. */ rc=optsetn('XWAIT',0); rc=system(x_cmd); /* Echo PRINTOFF command to the SAS Log. */ put x_cmd=; slctd_prt=slctd_prt; rc=rc; return; /**********************************************************************/ /* Example 6 */ /* EXMPL006.SCL - Demonstrate use of PROC DISPLAY. */ proc display c=scldemo.mypgms.exmpl001.scl; run; /**********************************************************************/ /* Example 7 */ /* EXMPL007.SCL - Batch submission from SCL template. */ INIT: /* Make temporary directory nodes list. */ tmp_lst=makelist(); /* Open directory to make list. */ rc=filename('CURNODE','**** pds dsn ****'); dir_id=dopen('CURNODE'); if dir_id lt 1 then do; put 'Directory Open Failed on MVS Host'; return; end; /* Put member names in list. */ mbr_cnt=dnum(dir_id); do i=1 to mbr_cnt; mbr_nm=dread(dir_id,i); if substr(mbr_nm,1,4) eq '**** member prefix ****' then rc=insertc(tmp_lst,mbr_nm,-1); end; rc=dclose(dir_id); rc=filename('CURNODE',''); call putlist(tmp_lst,'List of all MVS PDS Members',1); /* Open file in which to write program. */ rc=filename('INPGM', '**** temp program dsn ****', '', 'DISP=(NEW,KEEP,DELETE) SPACE=(TRK,(2,1)) LRECL=80 BLKSIZE= 4000 RECFM=FB'); file_id=fopen('INPGM','O'); rc=fput(file_id,"//**** JOB STATEMENT ****"); rc=fwrite(file_id); rc=fput(file_id,"//STEP1 EXEC SAS,OPTIONS='ERROR=1'"); rc=fwrite(file_id); /* Write DD statements. */ n=listlen(tmp_lst); do i=1 to n; dd_name='RAW'||put(n,Z3.); mbr_nm=getitemc(tmp_lst,i); dsn='**** pds dsn name ****('||dd_name||')'; dd_stmt='//'||dd_name||' DD DSN='||dsn||',DISP=SHR'; rc=fput(file_id,dd_stmt); rc=fwrite(file_id); end; rc=fput(file_id,'//SYSIN DD *'); rc=fwrite(file_id); /* Include SAS program. */ rc=fput(file_id,"%INCLUDE('**** SAS program dsn ****')"); rc=fwrite(file_id); rc=fput(file_id,'/*'); rc=fwrite(file_id); rc=fclose(file_id); rc=filename('INPGM',''); /* Submit program to internal reader. */ rc=filename('INPGM', '**** temp program dsn ****', '', 'DISP=SHR'); rc=filename('OUTRDR', 'A', '', 'SYSOUT=A PGM=INTRDR RECFM=FB LRECL=80'); inpgm_id=fopen('INPGM','I'); inrdr_id=fopen('OUTRDR','O'); do while (fread(inpgm_id)=0); rc=fget(inpgm_id,buffer,80); rc=fput(inrdr_id,buffer); rc=fwrite(inrdr_id); end; rc=fclose(inpgm_id); rc=fclose(inrdr_id); rc=filename('INPGM',''); rc=filename('OUTRDR',''); rc=rc; return; /**********************************************************************/ /**********************************************************************/