Questions tagged [sas]

The SAS language is a 4GL that underpins the SAS system, a suite of products centered around data processing and statistical procedures. For questions about code, please include your code and some data to reproduce your problem, either in datalines/cards statements or using a sashelp dataset like sashelp.class or sashelp.cars.

The SAS System is a proprietary suite of products used for business intelligence, data warehousing, data processing, and statistical analysis, across many industries, but particularly pharmaceuticals, finance and telecoms. It is available for (and often acting as a bridge between) mainframe, UNIX, Linux and Windows platforms.

The SAS System is a 4th generation programming environment, in that it includes a fully featured GUI with many user tasks able to be accomplished without coding. The SAS language itself is more powerful than the typical query language available in 4GLs, being more similar to a scripting language such as Python combined with built-in SQL and SQL-type queries.

SAS programs typically consist of two types of steps: data steps and proc steps. A data step creates a new data file or modifies an existing data file. Data steps can also serve to create user reports. Proc steps allow users to analyze data and provide user reports, such as summary statistics, charts of data, and correlations between variables. In addition SAS has ODS for Output in various formats like html, excel and pdf.

SAS also includes a macro language (also found in ) to conditionally control program code and improve readability.

SAS University Edition is an academic and free download for the SAS language available at http://support.sas.com/software/products/university-edition/

Questions about SAS that are on topic are questions about programming in SAS (writing code), questions about interacting with the programming environments related to SAS (Base SAS, Enterprise Guide, SAS Studio), or questions about SAS-related tools that are used in conjunction with programming (such as the prompt interface used in a programming context).

Questions about various SAS visual tools (such as SAS Visual Analytics) that are not used in conjunction with user written code, even if they could be used with writing code, are not on topic, nor is server administration. Please find appropriate communities for those questions, or the SAS community forums for any SAS related question that does not fit well here.


Well written SAS questions will include complete code to reproduce any issue you are having, and data to go with that code. Either use sashelp datasets (sashelp.class or sashelp.cars for example), or input your own data using a datalines statement, like so:

data have;
 input x y z;
 datalines;
1 2 3
4 5 6
7 8 9
;
run;

Examples of good questions that include datalines include How to use Boolean datatype in SAS? and PROC Report, multiple columns with same statistic. Examples of good questions using sashelp datasets include substr function with macro variable name and using where in sas macro when subsetting dataset.


Vendor website

15658 questions
9
votes
4 answers

Implementations of "The grammar of graphics" in statistical packages

I am aware that Leland Wikinson's ideas, as exposed in his book "The Grammar of Graphics" underlie ggplot2 implementation in R. But are there other implementations of the same ideas in other statistical packages (SAS or other)?
datanalytics.com
  • 986
  • 7
  • 11
9
votes
5 answers

Saving results from SAS proc freq with multiple tables

I'm a beginner in SAS and I have the following problem. I need to calculate counts and percents of several variables (A B C) from one dataset and save the results to another dataset. my code is: proc freq data=mydata; tables A B C / out=data_out ;…
Natalia
  • 101
  • 1
  • 1
  • 2
9
votes
5 answers

How can I read a SAS dataset?

I have a lot of files in SAS format, and I'd like to be able to read them in programs outside of SAS. I don't have anything except the base SAS system installed. I could manually convert each one, but I'd like a way to do it automatically.
Chris B.
  • 85,731
  • 25
  • 98
  • 139
9
votes
3 answers

How to count the number of observations in a SAS table?

I am very new to SAS. Now, I have a SAS data table as following: ID score ------------------- 01 1 02 3 03 4 04 2 Is there any way to save the number of observations in this table using only…
Munichong
  • 3,861
  • 14
  • 48
  • 69
9
votes
13 answers

Is there any syntaxhighlighter for SAS?

I need to post SAS code on my website. However, if I do write my HTML to highlight SAS cod it would take me a long time. How can I transform the SAS code into nice looking HTML counterpart?
CHEBURASHKA
  • 1,623
  • 11
  • 53
  • 85
9
votes
2 answers

get a the row number in a data step using sas

Is there a way to get to do a over partition to get the row number on sas? In sql I would go like: Select region,company, ROW_NUMBER() OVER(PARTITION BY region ORDER BY Name) From companyData; I want to do this in a data set preferably
user2467660
8
votes
7 answers

Is it possible to do a case-insensitive DISTINCT with SAS (PROC SQL)?

Is there a way to get the case-insensitive distinct rows from this SAS SQL query? ... SELECT DISTINCT country FROM companies; The ideal solution would consist of a single query. Results now look like: Australia australia AUSTRALIA Hong Kong HONG…
Rog
  • 4,075
  • 2
  • 24
  • 35
8
votes
3 answers

SAS can I make sas process observations backwards

I know that Sas starts with the observation at the top of a dataset when processing and proceeds to the next until it reaches the bottom observation, but is there an easy way to make sas process the bottom observation first and then work its way to…
sasnewbie
8
votes
2 answers

accessing R from SAS

I have both SAS (9.3) and R (2.14.0) installed on the same PC and I'd like to submit R statements within SAS using submit / R; and endsubmit;. However: SAS option RLANG is valid only at startup of the SAS System. The SAS option is ignored. Can you…
Marco
  • 9,334
  • 7
  • 33
  • 51
8
votes
5 answers

How to pad out character fields in SAS?

I am creating a SAS dataset from a database that includes a VARCHAR(5) key field. This field includes some entries that use all 5 characters and some that use fewer. When I import this data, I would prefer to pad all the shorter entries out to use…
purple_arrows
  • 265
  • 1
  • 2
  • 8
8
votes
2 answers

Change current folder

I'd like to specify the current folder. I can find the current folder: libname _dummy_ "."; %let folder = %NRBQUOTE(%SYSFUNC(PATHNAME(_DUMMY_))); %put &folder; and change it manually by double clicking the current folder status bar, but I'd prefer…
Murray
  • 660
  • 1
  • 8
  • 20
8
votes
2 answers

Reading huge sas dataset in python

I have a 50 gb SAS dataset. I want to read it in pandas dataframe. What is the best way to fast read the sas dataset. I used the below code which is way too slow: import pandas as pd df = pd.read_sas("xxxx.sas7bdat", chunksize = 10000000) dfs =…
Shanoo
  • 1,185
  • 1
  • 11
  • 38
8
votes
2 answers

How to use Boolean datatype in SAS?

In many mainstream programming languages you can use Boolean data-type (for instance, value can be either true or false) - to represent binary "true/false". Is there a Boolean data-type in SAS too? For example, in this code, the variable is_fruit is…
Atlas7
  • 2,726
  • 4
  • 27
  • 36
8
votes
2 answers

sas7bdat date format to R date format

I loaded a sas7bdat file using the sas7bdat package, but the dates are converted to a num like this: sas <- c(16922, 17045, 17014, 16983) I tried rPOSIX <- as.POSIXct(sas,origin='1960-01-01') as mentioned here but it's wrong. I don't have access…
spore234
  • 3,550
  • 6
  • 50
  • 76
8
votes
1 answer

What does `.Z` mean in SAS?

Apologies for such an entirely uninformed question, but I don't know any SAS and just need to know what one line of code does, so I hope someone can help. I have a loop over an array of variables, and an if clause that is based on a comparison to…
Nils Gudat
  • 13,222
  • 3
  • 39
  • 60