![Page 1: SAS Basics. Windows Program Editor Write/edit all your statements here. Log Watch this for any errors in program as it runs. Output Will automatically](https://reader036.vdocument.in/reader036/viewer/2022082519/5697bf781a28abf838c81b19/html5/thumbnails/1.jpg)
SAS Basics
![Page 2: SAS Basics. Windows Program Editor Write/edit all your statements here. Log Watch this for any errors in program as it runs. Output Will automatically](https://reader036.vdocument.in/reader036/viewer/2022082519/5697bf781a28abf838c81b19/html5/thumbnails/2.jpg)
Windows
Program Editor Write/edit all your statements here.
Log Watch this for any errors in program as it
runs. Output
Will automatically pop in front when there is output. Does not need to occupy screen space during program editing.
![Page 3: SAS Basics. Windows Program Editor Write/edit all your statements here. Log Watch this for any errors in program as it runs. Output Will automatically](https://reader036.vdocument.in/reader036/viewer/2022082519/5697bf781a28abf838c81b19/html5/thumbnails/3.jpg)
File Organization
Create subfolders in your Project folder for Data
Contains SAS datasets, with .sd2 extension Formats
Compiled version of formats, a file with .sc2 extension. Used for building classes of variables for looking at frequencies.
Output Save output files here. These are text files with
a .sas extension. Programs
All programs are text files with .sas ending.
![Page 4: SAS Basics. Windows Program Editor Write/edit all your statements here. Log Watch this for any errors in program as it runs. Output Will automatically](https://reader036.vdocument.in/reader036/viewer/2022082519/5697bf781a28abf838c81b19/html5/thumbnails/4.jpg)
Creating a dataset
Internal Data DATA datasetname; INPUT name $ sex $ age; CARDS; John M 23 Betty F 33 Joe M 50 ; RUN;
![Page 5: SAS Basics. Windows Program Editor Write/edit all your statements here. Log Watch this for any errors in program as it runs. Output Will automatically](https://reader036.vdocument.in/reader036/viewer/2022082519/5697bf781a28abf838c81b19/html5/thumbnails/5.jpg)
Creating a dataset
External Data DATA datasetname; INFILE ‘c:\folder\subfolder\file.txt’; INPUT name $ sex $ age; ; RUN;
![Page 6: SAS Basics. Windows Program Editor Write/edit all your statements here. Log Watch this for any errors in program as it runs. Output Will automatically](https://reader036.vdocument.in/reader036/viewer/2022082519/5697bf781a28abf838c81b19/html5/thumbnails/6.jpg)
Creating from an existing one
DATA save.data2 (keep = age income); SET save.data1; RUN;
DATA save.data2; SET save.data1; DROP age; TAX = income*0.28; RUN;
![Page 7: SAS Basics. Windows Program Editor Write/edit all your statements here. Log Watch this for any errors in program as it runs. Output Will automatically](https://reader036.vdocument.in/reader036/viewer/2022082519/5697bf781a28abf838c81b19/html5/thumbnails/7.jpg)
Permanent Data Sets LIBNAME save ‘c:\project\data’; DATA save.data1; X=25; Y=X*2; RUN;Note that save is merely a name you
make up to point to a location where you wish to save the dataset called data1. (It will be saved as data1.sd2)
![Page 8: SAS Basics. Windows Program Editor Write/edit all your statements here. Log Watch this for any errors in program as it runs. Output Will automatically](https://reader036.vdocument.in/reader036/viewer/2022082519/5697bf781a28abf838c81b19/html5/thumbnails/8.jpg)
What’s in my SAS dataset? PROC CONTENTS data=save.data1; RUN;
PROC CONTENTS data=save.data1 POSITION;
RUN;This will organize the variable list sorted
alphabetically and a duplicate list sorted by position (the sequence in which they actually exist in the file).
![Page 9: SAS Basics. Windows Program Editor Write/edit all your statements here. Log Watch this for any errors in program as it runs. Output Will automatically](https://reader036.vdocument.in/reader036/viewer/2022082519/5697bf781a28abf838c81b19/html5/thumbnails/9.jpg)
Viewing file contents
PROC PRINT data=save.data1; run;
PROC PRINT data=save.data1 (obs=5); VAR name age; RUN;
PROC PRINT data=save.data1 (obs=12); VAR age -- income; RUN;
![Page 10: SAS Basics. Windows Program Editor Write/edit all your statements here. Log Watch this for any errors in program as it runs. Output Will automatically](https://reader036.vdocument.in/reader036/viewer/2022082519/5697bf781a28abf838c81b19/html5/thumbnails/10.jpg)
Frequencies/Crosstabs PROC FREQ data=save.data1; TABLES age income trades; RUN;
PROC FREQ data=save.data1; TABLES age*sex; RUN;
![Page 11: SAS Basics. Windows Program Editor Write/edit all your statements here. Log Watch this for any errors in program as it runs. Output Will automatically](https://reader036.vdocument.in/reader036/viewer/2022082519/5697bf781a28abf838c81b19/html5/thumbnails/11.jpg)
Scatter Plot
PROC PLOT data=save.data1; PLOT Y*X; RUN;
![Page 12: SAS Basics. Windows Program Editor Write/edit all your statements here. Log Watch this for any errors in program as it runs. Output Will automatically](https://reader036.vdocument.in/reader036/viewer/2022082519/5697bf781a28abf838c81b19/html5/thumbnails/12.jpg)
Creating a Format Library PROC FORMAT LIBRARY=LIBRARY; VALUE BG 0 = 'BAD' 1 = 'GOOD' -1 = 'MISSING' ; VALUE TWO -1 = 'MISSING' -2 = 'NO RECORD' -3 = 'INQS. ONLY' -4 = 'PR ONLY' 0='0' 1='1' 1<-HIGH='2+' ; RUN;
![Page 13: SAS Basics. Windows Program Editor Write/edit all your statements here. Log Watch this for any errors in program as it runs. Output Will automatically](https://reader036.vdocument.in/reader036/viewer/2022082519/5697bf781a28abf838c81b19/html5/thumbnails/13.jpg)
Applying a format to a variable PROC DATASETS library=save; MODIFY data1; FORMAT trades ten.; RUN; QUIT;
This applies the format called ten to the variable trades. A subsequent PROC FREQ statement for trades will show the format applied. Note that ten must already exist in the format library for this to work.
![Page 14: SAS Basics. Windows Program Editor Write/edit all your statements here. Log Watch this for any errors in program as it runs. Output Will automatically](https://reader036.vdocument.in/reader036/viewer/2022082519/5697bf781a28abf838c81b19/html5/thumbnails/14.jpg)
Applying a format: Method 2
Data save.data2; SET save.data1; FORMAT trades bktrds ten. totbal mileage. ; RUN;
This is another way to apply formats when creating a new dataset (data2) from a previous one (data1) that has unformatted variables.
![Page 15: SAS Basics. Windows Program Editor Write/edit all your statements here. Log Watch this for any errors in program as it runs. Output Will automatically](https://reader036.vdocument.in/reader036/viewer/2022082519/5697bf781a28abf838c81b19/html5/thumbnails/15.jpg)
Random Selection of Obs. DATA save.new; SET save.old; Random1 = RANUNI(254987)*100; IF Random1 > 50 THEN OUTPUT; RUN; QUIT;The function RANUNI requires a seed number, and then
produces random values between 0 and 1, stored under the variable name Random1 (you can choose any name). The above program will create new.sd2, with about half the observations of old.sd2, randomly chosen.
![Page 16: SAS Basics. Windows Program Editor Write/edit all your statements here. Log Watch this for any errors in program as it runs. Output Will automatically](https://reader036.vdocument.in/reader036/viewer/2022082519/5697bf781a28abf838c81b19/html5/thumbnails/16.jpg)
Sorting and Merging Datasets PROC SORT data = save.junk; BY Age Income; Run;
PROC SORT data=save.junk OUT=save.neat; BY acctnum; RUN;
PROC SORT data=save.junk NODUPKEY; BY something; RUN;
![Page 17: SAS Basics. Windows Program Editor Write/edit all your statements here. Log Watch this for any errors in program as it runs. Output Will automatically](https://reader036.vdocument.in/reader036/viewer/2022082519/5697bf781a28abf838c81b19/html5/thumbnails/17.jpg)
Sorting and Merging Datasets
PROC SORT data=save.one; BY Acctnum; RUN; PROC SORT data=save.two; BY Acctnum; RUN;
DATA save.three; MERGE save.one save.two; BY Acctnum; RUN;
![Page 18: SAS Basics. Windows Program Editor Write/edit all your statements here. Log Watch this for any errors in program as it runs. Output Will automatically](https://reader036.vdocument.in/reader036/viewer/2022082519/5697bf781a28abf838c81b19/html5/thumbnails/18.jpg)
Sorting and Merging Datasets
DATA save.three; MERGE save.one (IN = a) save.two; BY Acctnum; IF a; RUN;
![Page 19: SAS Basics. Windows Program Editor Write/edit all your statements here. Log Watch this for any errors in program as it runs. Output Will automatically](https://reader036.vdocument.in/reader036/viewer/2022082519/5697bf781a28abf838c81b19/html5/thumbnails/19.jpg)
Using Arrays DATA save.new; SET save.old; ARRAY vitamin(6) a b c d e k; DO i = 1 to 6; IF vitamin(i) = -5 THEN vitamin(i) = .; END; RUN;This assumes you have 6 variables called a, b, c, d, e, and ,k
in save.old. This program will modify all 6 such that any instance of a –5 value is converted to a missing value.
![Page 20: SAS Basics. Windows Program Editor Write/edit all your statements here. Log Watch this for any errors in program as it runs. Output Will automatically](https://reader036.vdocument.in/reader036/viewer/2022082519/5697bf781a28abf838c81b19/html5/thumbnails/20.jpg)
Simple Correlations
PROC CORR data=save.relative; VAR tvhours study; RUN;
PROC CORR data=save.relative; VAR tvhours study; WITH Score; RUN;