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
0
votes
1 answer

SAS: What does this statement do?

I have the following statement within my SAS code taken from another person and I cannot figure out what it does. It is inside the DATA step when apparently creating a new variable named variable_X: variable_X = input(put(variable, variable_X.),…
doremi
  • 141
  • 3
  • 15
0
votes
4 answers

Sequences in SAS Tables

I'm looking to add a sequence column to my sas dataset, but according to ids and transaction dates. To illustrate, below is the table I'm referring to: ID | TXN_DT | 01 | 01JAN2020 | 01 | 01JAN2020 | 01 | 02JAN2020 | …
Lasmyr
  • 39
  • 4
0
votes
2 answers

How can I add observations to the existing dataset based on dates?

I have a dataset like this: data have; input date :date9. index; format date date9.; datalines; 31MAR2019 10 30APR2019 12 31MAY2019 15 30JUN2019 14 ; run; I would like to add observations with dates from the maximum date (hence from 30JUN2019)…
doremi
  • 141
  • 3
  • 15
0
votes
1 answer

SAS removing duplicates by the reappearance of chunks of records

I have a dataset with the reappearance of chunks of data in identical length groups of observations, such as: data have; input name $ identifier ; cards; mary 1 mary 2 mary 2 mary 4 mary 5 …
lydias
  • 841
  • 1
  • 14
  • 32
0
votes
0 answers

Matching two dissimilar datasets

I am trying to match two separate columns in two entirely different datasets, and I am looking for the best way to achieve this. It need not be a complete match, but also a partial match. I tried COMPGED method, but it took a long time, partly…
Chug
  • 31
  • 6
0
votes
1 answer

Converting a SAS data step with conditional statements to Python

Im trying to convert some old SAS Code to python. I have a conditional statement embbeded in my data step for SAS and want to do a similar thing but in python. SAS Code Below (variable names and values are generic names) DATA DF1; SET DF; IF (A =…
0
votes
1 answer

Sas data step keep statement from a text file

I have a table cust_base with 1000 variables. And I have a text file contents1 containing the names of 250 variables separated by tab, that I actually need to work with. I want to do something similar to: %include "/location/contents1.txt"; data…
IndigoChild
  • 842
  • 3
  • 11
  • 29
0
votes
2 answers

SAS Error: Null parameters for SUM are invalid

So I have a data named table1 as follows: Obs ID M_201812 M_201901 M_201902 M_201903 1 X1 1 . . . 2 X2 1 1 . . 3 X3 . 1 1 .…
IndigoChild
  • 842
  • 3
  • 11
  • 29
0
votes
1 answer

Creating calculated variables in one datastep

Any help is much appreciated. Thanks I would like to create a couple of variables with my transactional data I am trying to create variables 'act_bal' and 'penalty' using amount, type and Op_Bal. The rules I have are: For the first record, the id…
ckp
  • 579
  • 2
  • 10
  • 27
0
votes
1 answer

Take sum of dynamic number of columns in SAS

So I have a data box, as follows: Obs ID A B C D 1 X1 1 . . . 2 X2 1 1 . . 3 X3 . 1 1 . 4 X4 …
IndigoChild
  • 842
  • 3
  • 11
  • 29
0
votes
2 answers

How I can set data with specific system

I have little problem. As example tables HAVE1 and HAVE2 I want create table like WANT, set below specific row data from HAVE2 - to all column (since COL1 to COL19, without COL20) - and get table like WANT. How I can do? data HAVE1; infile DATALINES…
DarkousPl
  • 85
  • 1
  • 10
0
votes
2 answers

Dynamically determine columns to search in datastep SAS

I'm new to SAS, and need some assistance with a very basic problem. I have hundreds of individual datasets and I want to extract rows that match a certain diagnostic ID. The diagnostic ID's are listed in columns DX1-DX11. However some datasets have…
Tim
  • 367
  • 1
  • 6
  • 19
0
votes
3 answers

SAS IF THEN Statement for Range of Columns

I want to create a new column based on a range of columns(GAP1-GAP5). I wanted to use something like this: IF FIND(GAP1-GAP5,'New Start') THEN FILTER_NewStart=1 but got an error so had to use this: IF FIND(GAP1,'New Start') OR FIND(GAP2,'New…
0
votes
1 answer

How to compare price observations in rolling time intervals?

I would like to compare price observations inside a rolling time window of 10 minutes. Let's say I have the following table with prices (left most column) on the products and the time at which they were sold: data have; input @1 PRICE 1. @6 PRODUCT…
jjj
  • 35
  • 7
0
votes
2 answers

Define a filter with variable in data step with do loop- SAS

Good Morning, i've this problem. there are 2 dataset Dataset "ID Customer" where i have this: id | Customer Name | ----------------------------- 123456 | Michael One | 123123 | George Two | 123789 | James Three | and…