This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*How to selectively filter your list of variables in a SAS data set with a pattern but not one that uses SAS variable shortcuts; | |
options mprint symbolgen; | |
%macro select(lib =, ds_in=, pattern=, ds_out=); | |
proc sql noprint; | |
select nliteral(name) into :var_list separated by ' ' | |
from dictionary.columns | |
where libname = upcase("&lib") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*This is an example of how to search through a list of terms and see if a field contains any of the values*/ | |
*Make fake data to show example; | |
*terms to search for; | |
data terms; | |
set sashelp.baseball (obs=5); | |
search_term = substr(team,1,3); | |
keep search_term;; | |
run; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#This program centers all variables | |
#This is also called standardization - each variable minus the mean. | |
library(tidyverse) | |
#generate fake data | |
df <- structure(list(day = c(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
One common issue with using SQL pass through is that you sometimes want to use data that is on your SAS server. Rather than pass this information to the server, to be used in a subquery or join, you can pass the values directly by dynamically generating the code and lookup lists | |
*/ | |
%let age = 14; | |
data test; | |
set sashelp.class end = eof;; | |
where age = &age.; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data char_num; | |
char = "8.4"; output; | |
char = "10.5"; output; | |
run; | |
data char_date; | |
char = "2012-01-01";output; | |
char = "2014-02-08"; output; | |
run; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*This illustrates how to pipe a table and graph to ODS EXCEL | |
using macros. | |
1. Replace BY with WHERE statements | |
2. Add in ODS EXCEL options to name sheet | |
3. Wrap code in macro - note main ods excel statements are outside of the macro. | |
4. Create a list of origins to run this for | |
5. Call macro for each origin | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*This is an example of exporting data to excel, with each section going to a | |
separate sheet and each sheet taking the name of the group*/ | |
*sorts your data to use BY logic; | |
proc sort data=sashelp.cars out=cars; | |
by origin; | |
run; | |
*removes proc title and by line which are usually printed by default; | |
ods noptitle; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Author: Jeff Myers | |
Source: https://communities.sas.com/t5/Graphics-Programming/Sankey-Diagram-Decision-Tree-etc/m-p/719812# | |
*/ | |
data random; | |
call streaminit(123); | |
do id = 1 to 100; | |
do cycle=1 to 5; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*This is an example of how to control which output goes to which file*/ | |
ods html (ID="dest2") file='/home/fkhurshed/Demo1/testODS1.html'; | |
ods html (ID="dest3") file='/home/fkhurshed/Demo1/testODS2.html'; | |
ods html (ID="dest2") select BasicMeasures; | |
ods html (ID="dest3") select Quantiles; | |
proc univariate data=sashelp.class; | |
run; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*An example/demo of how to convert a macro variable list that is space delimited to comma delimited. | |
%Let weightvar = WEIGHT HEIGHT AGE; | |
*uses the translate function to replace spaces with commas. If VALIDVARNAME=ANY this may not work; | |
%macro addCommas(varList=); | |
%sysfunc(translate(&varList, %str(, ), %str( ))) | |
%mend addCommas; | |
*example recoding; |