A Robust Histogram
KanSAS Code
by
1y ago
I wanted to create a robust histogram to display the response time of a web site. To make a histogram you need to create your own statgraph using the Graphic Template Language (GTL). This requires a lot of research to see what is needed to make it all happen. Below is an image of the end result. I received some excellent assistance from Lelia at SAS technical support to add the percent sign (%) on the Y axis. This was accomplished by creating a custom format then assigning it to tickvalueformat= option inside linearopts=(). You will see within the proc template code that I am using a vertical ..read more
Visit website
When a problem comes along, you must whip it!
KanSAS Code
by
1y ago
While I have used the SAS FIND() function frequently, that is not the case for the similarly named FINDW() (find word) function. Taking advice from the 1980s band Devo, a problem came along and I was ready to whip it, whip it good! A pangram is a unique sentence that contains all the leters of the alphabet at least once. The name comes from the Greek root words pan, meaning "all," and gram, meaning "something written or recorded". The best-known English pangram is "The quick brown fox jumps over the lazy dog" and that is what I will use to test the issue. The FIND() function returns the start ..read more
Visit website
If only I had an Array
KanSAS Code
by
1y ago
Modeling data sets often have binary flag variable to indicate if a condition is true or false. Sometimes those indicators need to be collapsed or recoded into a single value based on conditions. See the below code for one technique to handle this. if s_del30postscratch_ind = 1 then curr_delinquency = "D30"; else if s_del60postscratch_ind = 1 then curr_delinquency = "D60"; else if s_del90postscratch_ind = 1 then curr_delinquency = "D90"; else if s_del120postscratch_ind = 1 then curr_delinquency = "D120"; else if s_del150postscratch_ind = 1 then curr_delinquency = "D150"; else i ..read more
Visit website
Last Column of DSN
KanSAS Code
by
1y ago
You can use the double dash ( -- ) shorthand to drop a list of columns in a data set based on names. I needed to do this for a list of data sets starting at a certain column to the very last column, but the last column name changed between data sets. The below macro utilizes low level SAS functions to return the name of the last column. So now I can do something like this: data x; set sashelp.class(drop = age -- %lastcolumn(sashelp.class));run;%macro lastcolumn(dsn); %local dsid retval; %let dsid = %sysfunc(open(&dsn)); %if &dsid %then %do; %let retval = %sysfunc(varname(& ..read more
Visit website
My Snippets - SQL Snapshot
KanSAS Code
by
1y ago
Now that SAS Studio is becomming more prevalant, I am moving away from Enterprise Guide into SAS Studio. A nice feature of SAS Studio is the ability to add your own code snippets. While working on a project, I often find myself having to trace thru a multitude of data sets and track the number of rows and columns at each step. I typically keep all those data sets in the WORK library. I have created the below code snippet to support that type of activity. The steps to save this snippet are to write the SQL statement as shown below then either right mouse click and select "Add to My Snippets" or ..read more
Visit website
Free Beer
KanSAS Code
by
1y ago
Ok, so maybe the title got you a bit excited but how do you feel about free SODA as in SAS OnDemand for Academics? SAS OnDemand for Academics is a free cloud based version of SAS that uses SAS Studio in your web browser as an editor. This means that there is no software to download and install and that with your credentials you can use SAS anywhere you have an internet connection. To get started you just need to create a SAS profile for a free account with SAS on this page. If you already have a profile you can use your email address and password to logon. Otherwise, click on the Don't have a ..read more
Visit website
Creating Sample Data
KanSAS Code
by
1y ago
Sample data plays important roles in testing and benchmarking applications. We need to be mindful of personally identifiable information or PII to not reveal actual user data. SAS does provide procedures such as surveyselect to create extended sample data from existing data but that can be risky if PII is not properly addressed. The use of SAS supplied test data such as SASHELP.CLASS or SASHELP.BASEBALL and the like are just too small to be of any value, especially when benchmarking. As a result, I have created a macro named sampledata that creates fictious data of any size you like in terms o ..read more
Visit website
Recursive Query with PROC SQL
KanSAS Code
by
1y ago
The SAS implementation of SQL is not as robust as most relational databases. One example where SAS falls short is in the area of recursive queries. I know that SQL Server and PostgreSQL handle recursive queries via the use of common table expressions or CTEs using the WITH statement. Hopefully SAS will add this feature in a future release since CTEs were included in the SQL:1999 standard. In the mean time, I have emulated an existing article "Learn PostgreSQL Recursive Query By Example". Please reference that article for additional details and to compare the different techniques. Credit must b ..read more
Visit website
When a problem comes along, you must whip it!
KanSAS Code
by
1y ago
While I have used the SAS FIND() function frequently, that is not the case for the similarly named FINDW() (find word) function. Taking advice from the 1980s band Devo, a problem came along and I was ready to whip it, whip it good! A pangram is a unique sentence that contains all the leters of the alphabet at least once. The name comes from the Greek root words pan, meaning "all," and gram, meaning "something written or recorded". The best-known English pangram is "The quick brown fox jumps over the lazy dog" and that is what I will use to test the issue. The FIND() function returns the start ..read more
Visit website
If only I had an Array
KanSAS Code
by
1y ago
Modeling data sets often have binary flag variable to indicate if a condition is true or false. Sometimes those indicators need to be collapsed or recoded into a single value based on conditions. See the below code for one technique to handle this. if s_del30postscratch_ind = 1 then curr_delinquency = "D30"; else if s_del60postscratch_ind = 1 then curr_delinquency = "D60"; else if s_del90postscratch_ind = 1 then curr_delinquency = "D90"; else if s_del120postscratch_ind = 1 then curr_delinquency = "D120"; else if s_del150postscratch_ind = 1 then curr_delinquency = "D150"; else i ..read more
Visit website

Follow KanSAS Code on FeedSpot

Continue with Google
Continue with Apple
OR