#2 Subsets

Image for post
Image for post

You can think of a subset as part of a larger group or a filter of a larger group. In this tutorial we will get a subset of the Cars table located in SASHELP. More specifically I want only cars who have the origin of Asia.

SASHELP is a permanent library that contains sample data like the Cars table. The table Cars contains 428 observations or rows.

/*Print all observations/rows in the table Cars */
proc print data= sashelp.cars;
run;
Image for post
Image for post
/*Create Asian Cars Data Set*/
data AsianCars;
set sashelp.cars;
where origin = 'Asia';
run;
/*Print the data from AsianCars*/
proc print data = AsianCars;
run;

Results: There were 158 observations read from the data set SASHELP.CARS

Image for post
Image for post

Now let’s make a subset of the cars table but this time we will keep only a few columns: make, model, origin, and MPG_City. We will also display every column except for the origin column when printing to the screen.

/*Create Asian Cars Data Set*/
data AsianCars;
set sashelp.cars (keep = make model origin MPG_City);
where origin = 'Asia';
run;
/*Print the data from AsianCars*/
proc print data = AsianCars;
var make model MPG_City;
run;

Results of New Data Set:

Image for post
Image for post

Results of Print Procedure

Image for post
Image for post

If you are interested in data science and data analytics after reading this article you should check out the website FiveThirtyEight.com they have many interesting articles and statistics on politics, sports, science, health, economics and culture, you can also check out my blog for more information on free tutorials and books on data analytics/ science. Thanks for reading this article, I hope you found it very helpful and enjoyable as I enjoyed writing it! Happy learning and I will see you all in my next article. Please leave many claps on here and share it, thanks for taking the time out of your busy day to read this article !

Check Out the following for content / videos on Computer Science, Algorithm Analysis, Programming and Logic:

YouTube Channel:
randerson112358: https://www.youtube.com/channel/UCaV_0qp2NZd319K4_K8Z5SQ

compsci112358:
https://www.youtube.com/channel/UCbmb5IoBtHZTpYZCDBOC1CA

Website:
http://everythingcomputerscience.com/

Video Tutorials on Recurrence Relation:
https://www.udemy.com/recurrence-relation-made-easy/

Video Tutorial on Algorithm Analysis:
https://www.udemy.com/algorithm-analysis/

Twitter:
https://twitter.com/CsEverything

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store