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
| proc sql noprint; | |
| select min(period) into :min_period TRIMMED | |
| from have; | |
| select max(period) into :max_period TRIMMED | |
| from have; | |
| quit; | |
| %put &min_period; | |
| %put &max_period; |
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 example demonstrates how to get a list of duplicates based on the key variables. | |
| KEY variables are placed in the BY statement. | |
| Any 'duplicates' according to the KEY variables are kept in the OUT= dataset | |
| */ | |
| *Generate sample data with duplicate KEY; | |
| data class; | |
| set sashelp.class sashelp.class(obs=5); | |
| 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
| data class; | |
| set sashelp.class; | |
| length category $20.; | |
| bmi = 703*(weight/(height**2)); | |
| if bmi < 18 then | |
| category='Under Weight'; | |
| else if 18 <= BMI < 25 then | |
| category='Normal'; | |
| else if 25 <= BMI < 30 then |
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
| /*Note that if you apply formats to your date they get grouped according to the format, so having a SAS date is advantageous. | |
| Here's a quick example that shows the calculating of yearly statistics from a data set.*/ | |
| proc means data=sashelp.stocks N NMISS min max mean median STACKODS; | |
| class date; | |
| format date year4.; | |
| var open high low; | |
| output out=want n= mean= sum= median= mean= / autoname autolabel; | |
| ods output summary = want2; | |
| 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
| /*Demo to show how to loop through a list of macro variables*/ | |
| proc sql noprint; | |
| select name into :name1- | |
| from sashelp.class; | |
| quit; | |
| %macro demo; | |
| %do i=1 %to 10; | |
| %put name&i=&&name&i; |
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
| /*Sample code that demonstrates how to export an excel file using SAS UE*/ | |
| proc export data=sashelp.class outfile='/folders/myfolders/Class.XLSX' dbms=xlsx replace; 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
| /*How to create 50 random numbers for every observation in your data set */ | |
| data want; | |
| set sashelp.class; | |
| do i=1 to 50; | |
| zv = rannor(0); | |
| output; | |
| end; |
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
| *create a sample data set; | |
| data have; | |
| do i=1 to 7000; | |
| x=rand('bernoulli', 0.4); | |
| output; | |
| end; | |
| run; | |
| *Set group size; | |
| %let group_size = 1000; |
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
| *generate fake data; | |
| data have; | |
| array a(17); | |
| do i=1 to 100; | |
| do j=1 to 17; | |
| a(j)=rand('bernoulli', 0.27); | |
| if rand('bernoulli', 0.1)=1 then |
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 code will search text files for a single word, search_string | |
| Originally via @schmuel here: | |
| https://communities.sas.com/t5/Base-SAS-Programming/Searching-SAS-code-for-keywords/m-p/390472#M93671 | |
| */ | |
| %let search_string = rename; | |
| %let suffix = sas; | |
| %let root=/folders/myshortcuts/My_Folders/; | |
| filename finp ("&root.sas_help/*.&suffix"); |