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

concat two numbers in sas proc sql

I have a table that has two numeric values called year and month. I would like to create a new table that has one value called ym which is just the concatenation of year and month. Here is an example: proc sql; create table test as select…
Alex
  • 19,533
  • 37
  • 126
  • 195
13
votes
4 answers

Join overlapping date ranges

I need to join table A and table B to create table C. Table A and Table B store status flags for the IDs. The status flags (A_Flag and B_Flag) can change from time to time, so one ID can contain multiple rows, which represents the history of the…
geebees
  • 131
  • 1
  • 4
13
votes
2 answers

SAS: concatenate different datasets while keeping the individual data table names

I'm trying to concatenate multiple datasets in SAS, and I'm looking for a way to store information about individual dataset names in the final stacked dataset. For eg. initial data sets are "my_data_1", "abc" and "xyz", each with columns 'var_1' and…
steadyfish
  • 847
  • 2
  • 12
  • 27
12
votes
2 answers

GBM Rule Generation - Coding Advice

I use the R package GBM as probably my first choice for predictive modeling. There are so many great things about this algorithm but the one "bad" is that I cant easily use model code to score new data outside of R. I want to write code that can be…
B_Miner
  • 1,840
  • 4
  • 31
  • 66
12
votes
3 answers

Macro returning a value

I created the following macro. Proc power returns table pw_cout containing column Power. The data _null_ step assigns the value in column Power of pw_out to macro variable tpw. I want the macro to return the value of tpw, so that in the main…
hungtx
  • 121
  • 1
  • 1
  • 3
12
votes
4 answers

Can anyone help me write a R data frame as a SAS data set?

In R, I have used the write.foreign() function from the foreign library in order to write a data frame as a SAS data set. write.foreign(df = test.df, datafile = 'test.sas7bdat', codefile = 'test.txt', package = "SAS") The SAS data file is written,…
Jubbles
  • 4,450
  • 8
  • 35
  • 47
12
votes
2 answers

Export pandas dataframe to SAS sas7bdat format

The flow I have in mind in this: 1. Export a sas7bdat from SAS 2. Import that file in python with pd.read_sas and do some stuff on in 3. Export the pandas dataframe to sas7bdat (or some other SAS binary fileformat). I thought that pd.to_sas would…
BogdanC
  • 1,316
  • 3
  • 16
  • 36
12
votes
1 answer

Parse a tables with unicode chars in variables from JSON with SAS BASE

I've faced with a problem on parsing JSON with unicode char in vars. So, I have the next JSON (example): { "SASJSONExport":"1.0", "SASTableData+TEST":[ { "\u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f":2, …
Sanek Zhitnik
  • 716
  • 1
  • 10
  • 25
12
votes
4 answers

List only the column names of a dataset

I am working on SAS in UNIX env and I want to view only the column name of a dataset. I have tried proc contents and proc print but both of them list a lot of other irrevelant information that I do not want as it fills up my putty screen and the…
siso
  • 135
  • 1
  • 1
  • 7
12
votes
2 answers

R Markdown equivalent in SAS

i wonder if there is a equivalent of R Markdown in SAS? Or how to do so in SAS? I want to have colored SAS code and its result below. link to R Markdown: http://rstudio.org/docs/authoring/using_markdown
Maciej
  • 3,255
  • 1
  • 28
  • 43
12
votes
10 answers

What's your best trick to break out of an unbalanced quote condition in BASE SAS?

As a base SAS programmer, you know the drill: You submit your SAS code, which contains an unbalanced quote, so now you've got not only and unclosed quote, but also unclosed comments, macro function definitions, and a missing run; or quit;…
Martin Bøgelund
  • 1,681
  • 1
  • 17
  • 26
11
votes
5 answers

sort and output records with SAS and R

I have the following data set PatientName BVAID Rank TreatmentCode TreatmentID DoseID Tim Stuart BVA-027 3 OP_TBC 1 1 Tim Stuart BVA-041 4 OP_TBC 1 1 Tim Stuart BVA-021 7 OP_TBC …
Makoto
  • 111
  • 5
11
votes
3 answers

In SAS, what are good techniques/options for catching syntax errors?

In the enhanced editor, the coloring might give you a hint. However, on the mainframe I don't believe there is anything, in the editor, that will help you. I use OPTIONS OBS=0 noreplace; The obs=0 option specifies that 0 observarions are read in…
Jay Corbett
  • 28,091
  • 21
  • 57
  • 74
11
votes
7 answers

XPT to CSV Conversion?

Perhaps this is the wrong place for this, but I'm not quite sure where to put it. I have a very large compressed SAS file in .XPT format. I want to convert it to a comma separated format. The file is too large to load in R. I do not have SAS on my…
John Doucette
  • 4,370
  • 5
  • 37
  • 61
11
votes
3 answers

Tell SAS not to add newly generated tables on the Process Flow

I have a SAS code that creates a lot of intermediary tables for my calculations. Thing is, I don't really care about this tables after the job is done, I only care to the finals results. But, everytime I run this code, SAS add all the generated…
cake
  • 1,336
  • 1
  • 13
  • 20