Questions tagged [datastep]

SAS datastep programming is the basic method of manipulating data in SAS, a 4G Statistical programming language.

This tag is intended for questions involving SAS datastep programming. It might be more appropriately answered by a SAS programmer, rather than a SAS user primarily focused on the statistical side.

SAS datastep programming involves anything between the 'data' statement and a step boundary (most commonly, 'run;', or another 'data' or 'proc' statement). It is used in SAS to input data from text files / database tables or other SAS programs, to manipulate data, and to output data to text files / database tables.

245 questions
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
4
votes
2 answers

apply keep and where together sas

I am working with sas to manipulate some dataset. I am using the data step to apply some condition to keep columns and filter on some values. The problem is that I would like to filter on columns that in the end I will not need, so I would like to…
Marco De Virgilis
  • 982
  • 1
  • 9
  • 29
4
votes
3 answers

Setting *most* variables to missing, while preserving the contents of a select few

I have a dataset like this (but with several hundred vars): id q1 g7 q3 b2 zz gl az tre 1 1 2 1 1 1 2 1 1 2 2 3 3 2 2 2 1 1 3 1 2 3 3 2 1 3 3 4 3 1 2 2 3 2 1 1 5 2 1 2 2…
J.Q
  • 971
  • 1
  • 14
  • 29
4
votes
3 answers

Set multiple datasets with similar names in sas

Suppose I have a varying number of datasets in my work environment, but all of which start with a similar name: name_abc, name_efg, name_1ky, etc. The datasets have the same variables and characteristics, and I want to set them all into one…
Lyle
  • 219
  • 1
  • 4
  • 12
4
votes
1 answer

SAS error message (FATAL: Code generation error detected during MISSING smear generation)

Does anyone know what this error message means? FATAL: Code generation error detected during MISSING smear generation. It occurs whilst concatenating approx 40 datasets. I believe it may be due to hitting memory limits from having too many…
Allan Bowe
  • 12,306
  • 19
  • 75
  • 124
3
votes
1 answer

Print all columns SAS with delimiter

I am trying to print out a delimited file, without having to specify all of the columns. I can get close, but the numeric columns are always quoted: DATA _NULL_; SET SASHELP.CARS (obs = 5 keep = Make Model EngineSize); FILE "foo.csv" DSD…
mlegge
  • 6,763
  • 3
  • 40
  • 67
3
votes
3 answers

SAS/ACCESS and data step on external DB

I have the following concern regarding SAS/ACCESS facility. Let's imagine that we have an external DB (i.e. Oracle), which we have assigned to a certain libname. Next, we do a simple operation on one of the tables within this DB, i.e. data…
kacperdominik
  • 194
  • 2
  • 10
3
votes
1 answer

How to read from two data sets by certain order?

Assume I have 2 data sets A and B: Data A; input data $; datalines; A1 A2 A3 ; run; Data B; input data $; datalines; B1 B2 B3 ; run; I whant to generate a data set with certain order as below : A1 B1 B2 B3 A2 B1 B2 B3 A3 B1 B2 B3 How to do that…
Gary Liao
  • 61
  • 5
3
votes
4 answers

Express "PUT all variables" in a data step to export SAS data

Goal: export an entire SAS dataset to a tab-delimited text file using a data step. Problem: In every example that I can find, such as this one, one must specify every variable in the data step following the PUT statement. Isn't there a simple…
zkurtz
  • 3,230
  • 7
  • 28
  • 64
3
votes
5 answers

SAS datastep/SQL select latest record from multiple records with same ID

For example I have a dataset as below: id Date 1 2000/01/01 1 2001/01/01 1 2002/01/01 2 2003/01/01 By datastep or sql, how could I get the record with id = 1 and latest Date 2002/01/01? Help is appreciated and thanks in advance.
Luke Henz
  • 137
  • 3
  • 5
  • 12
3
votes
1 answer

Explain the order in which SAS reads data step (conceptual)

I need to understand how SAS reads/executes data steps. When I've looked up info on how SAS reads data steps, all I seem to find is info on how it reads for merging purposes, which i don't understand in relation to a regular data step. Lets say, for…
Mike L
  • 486
  • 5
  • 16
  • 33
3
votes
1 answer

Modify a single observation in a SAS data set

Suppose I have the following data set: data people; input name $ age; datalines; Timothy 25 Mark 30 Matt 29 ; run; How can I change the age of a particular person? Basically, I want to know how to specify a name and tell SAS to change that…
synaptik
  • 8,971
  • 16
  • 71
  • 98
3
votes
5 answers

Data step/SQL Join/Merge/Union 2 datasets/tables and remove the same rows/observations

For example, I have 2 tables like this data have; input name $ status $; datalines; A a B b C c ;;;; run; 2nd table: data addon; input name $ status $; datalines; A a C f D d E e F f B z ;;;; run; How do I get the result…
Luke Henz
  • 137
  • 3
  • 5
  • 12
3
votes
1 answer

SAS Data Step counting nodes/edges in a graph

Suppose I have a directed graph represented in a dataset named links, which has two variables: from_id and to_id. I want to use SAS Data Step to do two things: (1) count the number of nodes, and (2) count the number of edges. Suppose the links…
synaptik
  • 8,971
  • 16
  • 71
  • 98
2
votes
2 answers

Flushing PDV variables

Is there a command or a quick way to set all the existing variables in the PDV to missing? I have some code which runs like this: Data example2; var1='A'; Var2='B'; Var3='C'; /* etc*/ output; Var1='B'; output; stop; run; once the first 'output'…
Allan Bowe
  • 12,306
  • 19
  • 75
  • 124
1
2 3
16 17