0% found this document useful (0 votes)
109 views6 pages

Sas 11-2

This document provides an overview of importing and working with data in SAS. It demonstrates how to import data from CSV and Excel files into SAS, perform basic data management tasks like filtering, sorting, and creating new variables. It also shows how to generate simple summary reports including frequency tables and bar charts to visualize the data.

Uploaded by

Marjo Kaci
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
109 views6 pages

Sas 11-2

This document provides an overview of importing and working with data in SAS. It demonstrates how to import data from CSV and Excel files into SAS, perform basic data management tasks like filtering, sorting, and creating new variables. It also shows how to generate simple summary reports including frequency tables and bar charts to visualize the data.

Uploaded by

Marjo Kaci
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

https://www.tutorialspoint.com/sas/sas_quick_guide.

htm

* 7.SAS programming tutorial;

proc print data=sashelp.cars;


run;
*log is commulative. u can clear it: new or edit/clear all;

* 8. Import a Comma-Separated File(CSV) into SAS;

data work.TestScores;
infile 's:\workshop\testscores.csv' dlm=',' firstobs=2;
input Gender $ SATScore IDNumber TesDate $;
run;

data work.TestScores;
infile 's:\workshop\testscores.csv' dlm firstobs=2;
input Gender $ SATScore IDNumber TesDate :date9;
run;

data work.TestScores;
infile 's:\workshop\testscores.csv' dlm firstobs=2;
input Gender $ SATScore IDNumber TesDate :date9.;
format TestDate date9.;
run;

proc import out=work.TestScores;


datafile="s:\workshop\testscores.csv"
dbms=csv replace;
getname=yes;
datarow=2;
run;

* 9. SAS programming tutorial: Importing data from exel into SAS;

*create namerange PartialBodyFat into exel;

libname exdat excel 's:\workshop\bodyfat.xlsx';

/*this is how import the exel data.


So i created library exdat and inside we find the sheet names as databases, and
the namerange*/

proc print data=exdat.'bodyfat2$'n; /*bodyfat2$ name of sheet*/


run;

data work.bodyfat2;
set exdat.'bodyfat2$'n;
where age>50;
run;

proc import out=work.bodyfat2


datafile="S:\workshop\bodyfat.xlsx"
dbms="exel replace";
range="bodyfat2$"n;
run;

* 10. Read a SAS Data set;

libname libsas 's:\workshop';

data work.lowerbody;
set libsas.Bodyfat2;
keep vase weight height hip thigh knee ankle;
run;

data work.lowerbody;
set libsas.Bodyfat2;
drop PctBodyFat1 PctBodyFat2 Density Age
Adioposity FatFreewt Neck Chest
Abdomen Biceps Forearm Wrist;
run;

* 11.Filter data in SAS;

data work.FemaleSAT13KPlus;
set libsas.testscores;
where gender='Female' and SATScore>1300;
run;

* 12.Create a new variable in SAS;

data work.bodybmi;
set libsas.bodyfat;
bmi=weight/(height*height)*703;
run;

data work.bodybmi;
set libsas.bodyfat;
bmi=weight/(height*height)*703;
bmi=round(bmi,.1);
run;

data work.bodybmi;
set libsas.bodyfat;
bmi=round(weight/(height*height)*703,.1);
run;

data work.bodybmi;
set libsas.bodyfat;
bmi=round(weight/(height*height)*703,.1);
Study='BFnov2013';
run;
* 13. Merge a microsoft excel file with a sas data set;

* 6.Reading and Generating CSV Files Using SAS Studio;


/** use snippets import csv file **/

proc print data=sashelp.cars;


run;
title; /** this gives the title of table cars

/** 8.Import a Comma-Separated File into SAS

write notepad and then click open the notepad file.

16.Sort Data Using SAS

proc sort data=libsas.titanic1 out=work.titanic2;


by Survived;
run;

proc sort data=libsas.titanic1 out=work.titanic2;


by Survived Age;
run;

proc sort data=libsas.titanic1 out=work.titanic2;


by descending Survived descending Age;
run;

17.Pring a Simple Listing with SAS

proc pring data=libsas.titanic;


run;

proc print data=libsas.titanic;


var Name Gender Age Survived;
run;
proc print data=libsas.titanic;
var Name Gender Age Survived;
where Survived=1;
run;

proc print data=libsas.titanic noobs;


var Name Gender Age Survived;
where Survived=1;
run;

proc print data=libsas.titanic(obs=25) noobs; /**disply first 25 observations **/


var Name Gender Age Survived;
where Survived=1;
run;

18.Create a Basic Summary Report Using SAS

proc mean data=sasuser.titanic;


var Age;
run;

proc mean data=sasuser.titanic;


var Age;
class Gender Survived;
run;

proc mean data=sasuser.titanic min max mean maxdec=2;


var Age;
class Gender Survived;
run;

19.Create a Basic Frequency Report Using SAS

proc freq data=sasuser.titanic;


tables Gender Class;
run;

proc freq data=sasuser.titanic;


tables Gender Class/nocum nopercent;
run;

proc freq data=sasuser.titanic;


tables Gender*Class; /**cross tabulation table**/
run;

proc freq data=sasuser.titanic;


tables Gender*Class/ nopercent; /**cross tabulation table**/
run;
proc freq data=sasuser.titanic;
tables Gender*Class/list; /**cross tabulation table**/
run;

proc freq data=sasuser.titanic;


tables Gender*Class/crosslist; /**cross tabulation table**/
run;

20.Create a Simple Bar Chart Using SAS

title 'Average Percent Body Fat For Different Age Groups'


proc sgplot data=sasuser.bodyfat3;
hbar agegroup / response=pctbodyfat1 stat=mean;
run;

proc sgplot data=sasuser.bodyfat3;


hbar agegroup / response=pctbodyfat1 stat=mean fillattrs=(color=lightblue);
run;

proc sgplot data=sasuser.bodyfat3;


hbar agegroup / response=pctbodyfat1 stat=mea fillattrs=(color=lightblue);
xaxis label='Mean Percent Body Fat' labelattrs=(size=12);
yaxis label='Age Group' labelattrs=(size=12);
run;

title 'Number of Subjects in each Age Group'


proc sgplot data=sasuser.bodyfat3;
hbaragegroup /fillattrs=(color=lightblue);
xaxis label='Number of Subjects' labelattrs=(size=12);
yaxis label='Age Group' labelattrs=(size=12);
run;

title 'Mean Percent Body Fat in each Age Group';


proc sgplot data=sasuser.bodyfat3;
hbar agegroup/ response=pctbodyfat1 stat=mean fillattrs=(color=ligtblue);
hline agegroup / stat=freq x2axis;
xaxis label='Number of Subjects' min=0;
x2axis label='Number of subjects' min=0;
yaxis label='Age Group' labelattrs=(size=12);
run;

proc sgplot data=sasuser.bodyfat3;


hbar agegroup/ response=pctbodyfat1 stat=mean fillattrs=(color=ligtblue);
hbar agegroup / stat=freq x2axis barwidth=.50;
xaxis label='Number of Subjects' min=0;
x2axis label='Number of subjects' min=0;
yaxis label='Age Group' labelattrs=(size=12);
run;

proc sgplot data=sasuser.bodyfat3;


vbar agegroup / response=pctbodyfat1 stat=mean fillattrs=(color=lightblue);
yaxis label='Mean Percent Body Fat' labelattrs=(size=12);
xaxis label='Age Group' labelattrs=(size=12);
run;

title;
proc sgplot data=sasuser.bodyfat3;
vbox pctbodyfat1 / category=agegroup;
xaxis label='Age Group' labelattrs=(size=12);
run;

You might also like