In DB2 it’s possible to save temporary tables in the schema SESSION.
Reset Display Manager SAS
It’s possible to insert the command below under keys in the Display Manager (DM) in SAS. The command will reset the line number in the log, clear the log and jump back to the editor.
gsubmit 'resetline';log;clear;wpgm;
Getting first megabytes of large file
You can use the DOS-command TYPE and MORE to get the first megabytes or gigabytes of a large file e.g. of TXT, XML, CSV etc.
This is done by piping the result into another file, there by getting only the first part of the file piped into the new file.
The DOS-command below will start piping the large file into the smaller new file.
type LARGE_SOURCE_FILE | more > SMALL_DESTINATION_FILE
You are not able to see the result from the DOS-command. You need to press the SPACE-key on your keyboard, because every time you press the SPACE-key a new page of the file will be showed and thereby piped into the SMALL_DESTINATION_FILE.
When you think you have done this enough times, then you have to press CTRL-C on your keyboard, this will terminate the type-command and you will have the SMALL_DESTINATION_FILE containing data from the LARGE_SOURCE_FILE.
Be aware that you will get the — more — pipe text in the file!
SQL-statement to find lowest observation in dataset
The SAS SQL-statement below will create a dataset containing all information for the observation with the lowest age in the dataset SASHELP.CLASS.
proc sql; create table CLASS as select * from SASHELP.CLASS group by AGE having AGE=min(AGE) ; quit;
The syntax for the SAS SQL-statement is showed below.
proc sql; create table <DESTINATION TABLE> as select * from <SOURCE TABLE> group by <COLUMN TO SEARCH> having <COLUMN TO SEARCH>=<FUNCTION>(<COLUMN TO SEARCH>) ; quit;
As you see the <FUNCTION> doesn’t have to be min (minimum), it can be any function working on the type of <COLUMN TO SEARCH> – numeric or char.
Enterprise Password Managers
Below is a list of enterprise password managers
https://www.vaultproject.io/
HashiCorp Vault secures, stores, and tightly controls access to tokens, passwords, certificates, API keys, and other secrets in modern computing. Vault handles leasing, key revocation, key rolling, and auditing. Through a unified API, users can access an encrypted Key/Value store and network encryption-as-a-service, or generate AWS IAM/STS credentials, SQL/NoSQL databases, X.509 certificates, SSH credentials, and more.
https://teampass.net/
eamPass is a Passwords Manager dedicated for managing passwords in a collaborative way by sharing them among team members.
Teampass offers a large set of features permitting to manage your passwords and related data in an organized way in respect to the access rights defined for each users.
Teampass is an Open-Source free to use product distributed in respect with OpenSource GNU GPL-3.0.
Info about SAS-datasets in the WORK-library
In SAS Enterprise Guide it is not very easy to see the size and number of observations in datasets in the WORK-library.
The macro below looks in the DICTIONARY.TABLES and gets these info for the WORK-library. Be aware that it will not work for views, because it’s not doing and actual count of the SAS-datasets.
/******************************************************************************** Author : Creation date : Description : Gets info about datasets in the WORK-library. Example : %countwork(print); ********************************************************************************* Input ----- &print : If not empty it will do a PROC PRINT of the dataset WORKDS created by the macro. ********************************************************************************* Output ------ WORKDS : Contains information about the datasets in the WORK-library. ********************************************************************************/ %macro CountWork(print); proc sql; create table workds as select libname , memname , typemem , nobs format=commax10.0 , filesize format=sizekmg. , nvar from dictionary.tables where libname eq 'WORK' order by nobs ; quit; %if &print. ne %then %do; proc print data=workds; run; %end; %mend;
Microsoft Team Foundation Server (TFS) and SAS
Below is shown how you can extract the current Microsoft Team Foundation Server (TFS) revision number for a given file into SAS and use it in your SAS program.
Be aware that Visual Studio 13 is used in the example below. It is uncertain if newer versions of Visual Studio will work.
%macro TFSRev(filename);
%let tfsver1=; %let tfsver2=; %let tfsver3=; /* The default path for the TF program tf.exe with Visual Studio 13. */
%let TFRev=C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\tf.exe;
filename tfver pipe “call “”&TFRev”” hist “”&filename”” “;
data _null_;
infile tfver;
input; /* The output is in three different lines. */
put _n_ _infile_; /* Puts the three different output lines in three diffent macrovariables called tfsver1, tfsver2 and tfsver3. */
call symput(‘tfsver’ !! put(_n_,1.), _infile_);
run;
/* Suppress output from SAS. */ options nosource;
%put Extracting TFS information from: &filename;
%put; %put &tfsver1; %put &tfsver2; %put &tfsver3; option source;
%mend;
%TFSRev(C:\TEMP\sasprogram.sas);
You can now use the three diffent macrovariables called tfsver1, tfsver2 and tfsver3 in your program.
Microsoft Visual Studio Team Foundation Server 2013 Power Tools might be needed.
https://marketplace.visualstudio.com/items?itemName=TFSPowerToolsTeam.MicrosoftVisualStudioTeamFoundationServer2013Power
You might also want to have a look at this blogpost regarding SVN.
Automatically analyzing and documenting SAS-code
In SAS Enterprise Guide and SAS-DI you have the possibility to analyze the code for a SAS-program.
The picture below shows the Analyze Program option in SAS Enterprise Guide.
Analyzing the code should result in a conversion of the SAS-code to a SAS Enterprise Guide flow or SAS-DI flow. But none of these code analyzers are very good. Depending on the complexity of the SAS-code you put into the analyzer, they will leave you with a more or less successful conversion. And more times than not they will fail at doing the job.
But SAS comes with a procedure PROC SCAPROC that does a really good job at analyzing and documenting SAS-code.
Below is an example.
proc scaproc; record '<PATH>' attr expandmacros; run; proc scaproc; write; run;
The links below gives you further descriptions of PROC SCAPROC and its options. There’s also a guide on how to do a graphical presentation of the result fra PROC SCAPROC.
Overview of the SCAPROC Procedure
http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a003199745.htm
Program for parsing the output from PROC SCAPROC to create a data set with inputs and outputs.
http://support.sas.com/kb/58/047.html
Innovative Performance Improvements Through Automated Flowcharts In SAS
http://support.sas.com/resources/papers/proceedings16/11580-2016.pdf
Automatically create diagrams showing the structure and performance of your SAS code
http://support.sas.com/resources/papers/proceedings17/1104-2017.pdf
Uniqueness in data
The SAS-macro below will tell you if a variable in a dataset is unique.
/******************************************************************************** Author : Creation date : ddmmmyyy Description : Gets info about uniqness in a SAS-dataset. Example : %uniq(sashelp.class, name, print) ********************************************************************************* Input ----- &datset : The dataset to test. &variable : The variable to test for uniqueness. &print : If the output/result should be shown in a PROC PRINT. ********************************************************************************* Output ------ freq_result : Dataset sorted with doublets as first rows. freq_result_doublets : Data containing only the doublets. ********************************************************************************/ %macro uniq(dataset, variable, print); proc freq data=&dataset.; tables &variable / noprint out=freq_result; run; proc sort data=freq_result; by descending count; run; data freq_result_doublets; set freq_result; where count gt 1; run; proc sql noprint; select count(*) into :doublets from freq_result_doublets where count gt 1 ; quit; %put --------------------------------------------------------------------------------------------; %put NUMBER OF DOUBLETS IN [%upcase(&dataset.)] FOR VARIABLE [%upcase(&variable.)]: &doublets.; %put --------------------------------------------------------------------------------------------; %if &doublets. eq 0 %then %do; %put !!!! NO DOUBLETS !!!; %put --------------------------------------------------------------------------------------------; %end; %if &print. ne %then %do; proc print data=freq_result; run; %end; %mend;
Directory for SAS-macros
The code below will give you the path of all the directories containing macros in the SASAUTOS in your SAS-session.
%put %sysfunc(getoption(sasautos)); filename _all_ list;