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
6
votes
2 answers

how to concatenate each record within one observation in SAS

I wonder whether it's possible to concatenate each record within one observation with SAS code. E.g. Here is the original data set 1st_name 2nd_name 3rd_name .....last_name abc def ghi ..... xyz Now I want to add a variable that…
mj023119
  • 675
  • 5
  • 12
  • 19
6
votes
4 answers

SAS: Calling one macro from another...Order of Macro Definitions

In my code I have several macros. Macro A is the main macro. Macro A then calls macro B which in turn calls macro C. In SAS, do I have to define them in backwards order? In other words, do I have to define macro C first, then macro B, then…
JT.
  • 85
  • 1
  • 1
  • 8
6
votes
2 answers

pandas read_sas "ValueError: Length of values does not match length of index"

I need some help... I got some troubles reading my sas table in python using the pandas function read_sas. I got the following error: "ValueError: Length of values does not match length of index". Here is the code I run: import pandas as…
RagNar
  • 61
  • 1
  • 2
6
votes
3 answers

Does SAS have a equivalent function to all() or any() in R

In R you can perform a condition across all rows in a column variable by using the all() or any() function. Is there an equivalent method in SAS? I want condition if ANY rows in column x are negative, this should return TRUE. Or, if ALL rows in…
MWw
  • 150
  • 1
  • 8
6
votes
3 answers

How to sort data using Data step in SAS

I want to sort data in SAS data step. What exactly I mean is: the work of proc sort should be done in data step. Is there any solution?
Saran
  • 79
  • 1
  • 8
6
votes
4 answers

SAS - Define array of letters

Is there a shorthand in SAS for defining a sequence of letters in an array? Many languages possess a mechanism for doing so easily and I imagine SAS does too, although I'm unable to find a reference for it. For instance, in R I could do > x <-…
Lorem Ipsum
  • 4,020
  • 4
  • 41
  • 67
6
votes
1 answer

Standard errors discrepancies between SAS and R for GLM gamma distribution

I am comparing GLM output from R and SAS of a model with a Gamma distribution. The point estimations are identical, but they have different estimation of the standard error and therefore different p-values. Does anyone know why? I am wondering if R…
YDao
  • 325
  • 2
  • 15
6
votes
1 answer

How can I create pivot table in SAS?

I have three columns in a dataset: spend, age_bucket, and multiplier. The data looks something like... spend age_bucket multiplier 10 18-24 2x 120 18-24 2x 1 35-54 3x I'd like a dataset with the columns as…
Demetri Pananos
  • 6,770
  • 9
  • 42
  • 73
6
votes
3 answers

Save sas data set file to a local folder on server

Is is possible to save SAS data set (sas7bdat) to a local folder on server? For example c:\Work folder. I know only proc export to csv. Thank you.
6
votes
2 answers

SAS: Individual Table Titles for PROC FREQ or PROC REPORT?

Instead of performing multiple separate PROC FREQ procedures on a very large data set, I'd like to improve efficiency by performing a single PROC FREQ with multiple TABLE statements. Our QA process requires table titles which is simple with a single…
kstats9pt3
  • 799
  • 2
  • 8
  • 28
6
votes
2 answers

How can I import SAS format files into R?

I am trying to analyze data from the 2012-2013 NATS survey, from this location. There are three files in the zip folder there, labelled 2012-2013 NATS format.sas, formats.sas7bcat and nats2012.sas7bdat. The third file contains the actual data, but…
KVemuri
  • 194
  • 1
  • 16
6
votes
2 answers

Prompted to Save Changes on file created with EPPlus

I am creating a series of Excel Workbooks using EPPlus v3.1.3. When I open the newly created files, if I close it without touching anything it asks me if I want to save my changes. The only thing I've noticed changes if I say "yes" is that the…
yammerade
  • 629
  • 8
  • 20
6
votes
8 answers

How to find max value of variable for each unique observation in "stacked" dataset

Sorry for the vauge title. My data set looks essentially like this: ID X 18 1 18 1 18 2 18 1 18 2 369 2 369 3 369 3 361 1 what I want is to find the max value of x for each ID. In this dataset, that would be 2 for ID=18 and 3 for…
joey
  • 71
  • 1
  • 1
  • 4
6
votes
1 answer

SAS, programmatically export metadata object spks

In SAS, I have a folder structure that contains a large number of SAS table metadata. To migrate from one environment to another, we need to manually create a large number of spks and push them to Git. This is problematic because it (a) takes time,…
jaamor
  • 317
  • 3
  • 15
6
votes
1 answer

SAS libname syntax to connect to SQL Server via ODBC

I've googled for a few days and can't get this working. I'm using SQL 2014 and the adventureworks database. I've got SAS 9.3. I've tried different ODBC settings, as in setting a default database, using Windows login, or SQL login. Different…
doorlord
  • 61
  • 1
  • 3