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
7
votes
5 answers

sas informat datetime

Can anyone advise on the appropriate SAS informat to read in a datetime (dd/mm/yyyy hh:mm) ??? eg data _null_; informat from_dt datetime????.; input from_dt ; put from_dt=; cards; 01/01/1960 00:00 ;run;
Allan Bowe
  • 12,306
  • 19
  • 75
  • 124
7
votes
2 answers

Converting Repeated Measures mixed model formula from SAS to R

There are several questions and posts about mixed models for more complex experimental designs, so I thought this more simple model would help other beginners in this process as well as I. So, my question is I would like to formulate a repeated…
baha-kev
  • 3,029
  • 9
  • 33
  • 31
7
votes
3 answers

reading next observation's value in current observation

I've a dataset called 'input' with the following observations ID Salary 10 1000 20 2000 30 3000 40 4000 I need an output dataset with following observations ID Salary Next_row_Salary 10 1000 2000 20 2000 3000 30 3000 4000 40 4000 null …
athresh
  • 553
  • 6
  • 11
  • 24
7
votes
3 answers

Treat missing values as zero in SAS where clause

Is there an equivalent of the Oracle NVL function in SAS? For example, if I have a where clause in SAS that says: where myVar > -2; it is not going to include any rows that have myVar = . If I want to treat missing values as zero, i have to…
Adnan
  • 2,949
  • 4
  • 29
  • 45
6
votes
2 answers

How to create nice tables using PROC REPORT and ODS RTF output

I want to create a 'nice looking table' using the SAS ODS RTF output and the PROC REPORT procedure. After spending the whole day on Google I've managed to produce the following: The dataset DATA survey; INPUT id var1 var2 var3 var4 var5 var6 ; …
Gordon
  • 83
  • 1
  • 1
  • 6
6
votes
2 answers

How do I get SAS encoding option programmatically?

How do I find out the SAS global encoding option programmatically? I can run proc options, and it will give me the answer, but I need to do it from code. I am hoping for an answer on the lines of "look at the macro symbol &sysencoding", but this…
Simon Nickerson
  • 42,159
  • 20
  • 102
  • 127
6
votes
4 answers

How do you print the last observation of a SAS data set?

I have a data set with 1000 observations. I want to only print out the last observation. Using the following: proc print data=apple(firstobs = 1000 obs = 1000); run; I can get the last observation. But I have to know in advance that my data set…
NebulousReveal
  • 562
  • 2
  • 7
  • 19
6
votes
6 answers

function to track the changes in a field

I need a function (using base SAS or RStudio) that will enable me to determine the ID numbers as of a certain date and the original (root) ID numbers as of the start date. The dataset includes the old ID, the new ID, and the date the ID changed. …
Reza
  • 59
  • 3
6
votes
1 answer

Deleting all datasets in a library

This probably has a really simple answer. How would I go about deleting all the datasets in a library? I did something like proc datasets library=lib; delete _all_; quit; but that just tries to delete the dataset called _all_. Do I have to…
Hong Ooi
  • 56,353
  • 13
  • 134
  • 187
6
votes
2 answers

How to create a sas dataset with one variable where each value is increased by a constant step?

This would be a junior sas question. I have a lower bound, say, 1 and an upper bound, say, 10 and I want to create a dataset with a single variable, with 10 observations from 1 to 10, step at 1. How can I do this convinently in sas? Thanks for any…
Steve
  • 4,935
  • 11
  • 56
  • 83
6
votes
4 answers

proc sql join in SAS that is closest to a date

How can I do a one-to-many join between two datasets with proc sql in SAS to obtain the record in Dataset B is closest to a value in Dataset A? Dataset A #Patient #Date of Dose 001 2020-02-01 Dataset B # Patient # Lab…
Glenn
  • 436
  • 1
  • 3
  • 12
6
votes
1 answer

SAS macro for laboratory values

I'm attempting to create a SAS macro that will generate a shift table for laboratory values. I have the following data: Study Subject Lab Measure Range Group Visit Study1 001 …
statsguyz
  • 419
  • 2
  • 11
  • 35
6
votes
2 answers

SAS trigger error in SAS program executed from SAS-EG

I need to get SAS to trigger an error if a certain condition is not meet i have tried to use abort return n, abort abend etc.. but they all seems to to disconnect the entire session where i only want to get an error like with syntax etc. It is a…
havmaage
  • 573
  • 7
  • 25
6
votes
5 answers

extracting decision rules from xgboost in python

I want to use xgboost in python for my upcoming model. However since our production system is in SAS, I am trying to extract decision rules from xgboost and then write a SAS scoring code to implement this model in SAS environment. I have gone…
Ved
  • 93
  • 2
  • 4
6
votes
2 answers

SAS macro variable change

In general how do we deal with the situation where macro variables need to be modified inside a macro; for example, suppose I have this macro: %macro test (arg=); array arrayone [&arg]; /* This is ok */ array arraytwo [&arg+1] /* This is not ok.…
francogrex
  • 465
  • 1
  • 4
  • 17