Skip to main content

Posts

How to run multiple SAS code in batch?

Issue: I have multiple SAS code file which I have to run sequentially. How to do that? Solution: Create a shell script file to invoke the sasbatch.sh. myprogram.sh: #!/bin/bash nohup /opt/sas/config/Lev1/SASApp/BatchServer/sasbatch.sh /home/sas/$1 -xcmd -nodms -log /home/sas/logs/$1.log -print /home/sas/listing/$1.lst & In above command you need to change the path depending on your environment. For example: in your organization the sasbatch.sh file may be in different location.  Create SAS file to call your SAS program: myprogram.sas: filename src '/sas//programs'; filename src1 '/home/sas/'; %include src(autoexec.sas); %include src1(first.sas); %include src1(second.sas); %include src1(third.sas); In the above code, I have pointed filename statement to where my autoexec.sas and SAS programs are located. I have mentioned src as /sas/programs, it is the location where my autoexec.sas file present. I have mentioned  src1...

How to append log instead of creating new log for each run in SAS?

Issue: My program runs every hour. I need to create one log per day. So I need to append all the log generated by the code to a single file. Next day it should create the log in new file. How to do that? Solution: Use the logparm attribute as append. This option will append the log on the same file. -logparm "open=append" The batch code will be: /opt/sas/config/Lev1/SASApp/BatchServer/sasbatch.sh -sysin "myprogram.sas" -log "myprogram_`date +"%Y-%m-%d"`.log" -logparm "open=append" -print -noterminal You can see I have used date command to make it daily. You can change the occurence using that command. For more details about Logparam follow the below link: http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002303556.htm

SAS code to get all the table name under the library

Issue: SAS Admins were usually asked how many libraries do we have? What are the tables under the library? Here is the code to get all the table name under the library. Solution: Say I have a library named as Oracle Scoring and its libref is orascore then my code will be PROC SQL;      SELECT *      FROM sashelp.vmember      WHERE libname = " orascore  "   ; QUIT; In above code you need to just replace orascore with the libref of your library in your environment.  If you want to search for the table with specific pattern then you can use below code PROC SQL;      SELECT *      FROM sashelp.vmember      WHERE libname = " orascore  " and memname like " pattern "   ; QUIT;

Which license should I apply if I have more that one?

Issue: Our SAS environment license was about to expire. We ordered SAS License from SAS. They provided with two license for server with similar products. We are confused with which license to apply in our environment. Solution: Whenever we get license from SAS, it is always overwhelming. Because they provide license for Windows (SAS Clients) and Linux (SAS Server). You receive almost 8 to 10 text files including the renewal instructions. The easy way to figure out which license to apply for our environment is site number. Yes, don't get deviated by product name which will be misleading. In our environment we used to apply the license named as pre-production in prod. So it is not the recommended to apply license based on SITEINFO NAME. Always apply license based on the SITE= number. Run PROC SETINIT; RUN; in your server. You will get the site number. See which license have the same license number provided by SAS Tech Support. Apply that license in your environment to avoid a...

SAS code to find whether library is preassigned or not

Issue: How to find whether the library is pre-assigned or not? Solution: I got the below code from SAS Tech support. It will show all library names, engine, path and pre-assigned details. data metadata_libraries;   length liburi upasnuri $256 name $128 type id $17     libref engine $8 path mdschemaname schema $256     preassign $ 1 mdCreated mdUpdated $ 18;   keep name libref engine path mdschemaname schema preassign mdCreated mdUpdated;   call missing(liburi,upasnuri,name,engine,libref,preassign,mdCreated,mdUpdated);   /* Get each Library object */   nlibobj=1;   librc=metadata_getnobj("omsobj:SASLibrary?@Id contains '.'",nlibobj,liburi);   /* For each library, retrieve the libref, engine, path */   do while (librc>0);      /* Get Library attributes */      rc=metadata_getattr(liburi,'Name',name);      rc=metadata_ge...

What are the process that run when SPDS server is started in SAS?

Issue: How to check SPDS process is up or not. Solution: After you start SPDS server following process should be running. spdsnsrv - Name server component Central starting point for SPD server spdssnet - SPD SNet server component Interface between clients other than SAS clients and the name server spdsbase - SPD user proxy Process started by the data server for each user access or query. spdsserv - Data server component Validates the user credentials and starts a SPDSBASE user proxy spdslog - Logging process Writes the server name server, and snet server logs and recycles the logs at specified times. Note: data server and proxy process should always run on the same machine because proxy process is started by data server process. Other process can run in different machine.

Find column name of all SAS table that matches specific patter

Issue: I need to find out all the column name for all the table in a specific library, table name with specific string. Solution: To get all the column name for all the table in all the library use below code: PROC sql;   SELECT name     FROM dictionary.columns; QUIT; To get column name from specific library: PROC sql;   SELECT name     FROM dictionary.columns     WHERE libname='MYLIB'; QUIT; In the place of MYLIB use the libref of the library. To get column name for specific table: PROC sql;   SELECT name     FROM dictionary.columns     WHERE libname='MYLIB' and memname like 'EWF%'; QUIT; The above query will get you the result for all the table that contains string starting with EWF. Reference:  http://www2.sas.com/proceedings/sugi30/070-30.pdf