EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Data Science Data Science Tutorials SAS Tutorial SAS Command
 

SAS Command

Priya Pedamkar
Article byPriya Pedamkar

Updated March 2, 2023

SAS Command

 

 

Introduction to SAS Commands

SAS full form is the Statistical Analysis System. It has been provided by the SAS Institute in the year 1970. It is the software that is used for doing the statistical analysis, graphing and presenting the data. In this, there are two categories to present and analyze the data that are DATA step and PROC step. DATA step is mainly used for providing the data management like reading the data, Data transformation and creating or removing the variables. PROC step used to perform a wide variety analysis of the data. There are various commands available to achieve the presentation and analysis of data.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

Basic SAS Commands

1. Proc Print: It is used to view SAS data file in the output window.

Example:

proc print data= Grades;
Run;

2. Proc contents: It is used to check the content of the SAS Command data file in the output window

Example:

proc contents data=Grades;
Run;

3. Proc means: It is used to see the basic statistics of data. It provides the value of the mean, max, and min of the numeric values or variables.

Example:

proc means data= Grades;
Run;

4. Proc Freq: It is used to analyze the data and frequency of variables created and for tables

Example:

proc freq data=Grades;
Run;

Example:

proc freq data=Grades;
Tables a*b;
Run;

5. Proc sort: It is used to sort the SAS data file.

Example:

proc sort data=Gardes; Out= name by name;
Run;

6. Proc reg: It is used for one of the general-purpose procedure for SAS regression analysis.

Example:

proc reg data= Grades;
Run;

7. Proc gplot: It is used to plot the two values or more on axes.

Example:

proc gplot data=Grades;
Plot a*b;
a = vertical axis,
b = horizontal axis;
Run;

8. PROC transpose: It is used to convert rows into columns in the data set.

Example:

proc transpose data= Grades out= Field;
By name; var result; id col;
Run;

9. Proc Gchart: It is used to create the pie chart histogram.

Example:

proc Gchart data=grades;
Vbar age;
Run;

10. Proc report: It is used to create the report from the data set.

Example:

proc report data=Grades;
Column A;
Define A / display;
Run;

Intermediate SAS Commands

11. Libname: It is used to create the SAS library.

Example:

Libname NewLib 'C:\Grades';

12. Filename: It is used to specify the external data file.

Example:

Filename AName 'C:\Grades';

13. Infile: It is the statement that used to read an external data file.

Example:

Filename AName 'C:\Grades';
DATA SAS;
INPUT A B;
Infile AName;
Run;

14. If-Then: It is the statement used to execute different functions.

Example:

DATA AB;
IF A>B then message='A is greater';
Else message='B is greater';
Run;

15. Keep: It is the statement used to keep the variable that is required in the data set.

Example:

Data New;
SET version;
Keep name year price;
Run;

16. Label: It is a function to change the label of the variable.

Example:

Data ABC;
Label text “Hello, world”;
Run;

17. Length: It is used to change the length of the variable.

Example:

Data ABC;
Length text $10.;
Run;

18. Format: It is used to change the format of the variable.

Example:

Data ABC;
Format date yymmdd10.;
Run;

19. Input: It is used to convert the character value into a numeric value.

Example:

Data ABC;
A = " 10 ";
B= input (a, best.);
Run;

20. Log: It is used to convert the numeric value into a logarithm.

Example:

Data ABC;
A = 10;
B = log(a);
Run;

Advanced SAS Commands

21. Mean, Min and Max: It is used to compute the mean, minimum and maximum set of numeric values.

Example:

Data Mathdata;
A= 10;
B=20;
C= mean (a,b);
D= Min(a,b);
E= Max(a,b);
Run;

22. Rename: This Command is used to rename the variable.

Example:

Data mathdata;
A= 20;
Rename a= b;
Run;

23. Square root/ Square: It is used to calculate the square and the square root of the numeric value.

Example:

Data mathdata;
A= 4;
Square= a**2;
Sqroot = a**(1/2);
Run;

24. Mathematical functions: To perform basic mathematical functions.

Example:

Data mathdata;
Set Math;
Price = sum (of P1, P2);
Diff = D1 - D2;
M = M1 * M2;
Div= Div1 / Div2;
Run;

25. Substr: It is used to get the partial text from the text value.

Example:

Data Mathdata;
Text = "Hello World";
Text1= substr(Text, 6, 2);
Run;

26. Input and data line statement: It is used to create the data set with specified content.

Example:

DATA ABC;
Input A B C;
DATALINES;
1 2 3
4 6 9
;
Run;

27. Merge: It is used to merge multiple data set into one.

Example:

Data ABC;
Merge name John;
By ID;

Tips and Tricks to Use Commands

  • Think before programming, check all the criteria that need to cover.
  • Keep it simple.
  • Make the data sets easier to understand by putting the data that you need, helps in saving the disk space.
  • Use functions for the data conversion.
  • Avoid infinity means division by zero.
  • Use Null when you do not need to create the data set.
  • Assign the constant value to a variable in retain statement.
  • Use NoEquals option on sorting which helps in saving the time and memory.

Conclusion

Everyone has its own way to achieve the end result, these can be the same or different for the different people. There are many ways to find one result and while using the Commands software, one might get many ways to achieve the same result in different ways. It has been observed that more you learn and more you go through the documentation of commands, the more benefit you will get to achieve the results and help in the long run.

The above mentioned SAS commands are mainly used in SAS software programming. The things are mainly covered around DATA and PROC. It is an easy tool or software to use, which is simple in writing means writing the commands in simple English as you have already seen above commands. It is easy to use, learn and write.

Recommended Articles

This has been a guide to SAS Commands. Here we have discussed basic as well as advanced and some immediate SAS Commands. You may also look at the following article to learn more –

  1. Uses of Tableau Commands
  2. How to use the HBase Commands
  3. Uses of MongoDB Commands
  4. Importance of Pig Commands

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW