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 - lag by acct id?

Not sure if I need to use lag for this. But here's what I want to do. Here is the data I have... acct sort_order type 111111 1 standard 111111 1 standard 111111 2 non-standard 111111 3 …
user2941280
  • 285
  • 3
  • 9
  • 16
0
votes
1 answer

SAS: Stack files after checking that they exist

I am going through a bunch of files that are partitioned by calendar year and other variables. What I wanted to do is to partition them by fiscal year (based on a date variable that exists on the records). For example, to create FY2010 file, I would…
0
votes
1 answer

SAS Data Step programming - explain dataset(obs=0)

Could you please explain why none the data step statements are processed if we set the (obs=0) data set option in the (wrong) example below? data temp; x=0; run; data wrong; set temp(obs=0); x=1; y=1; output; y=2; …
jaamor
  • 317
  • 3
  • 15
0
votes
1 answer

Creating dataset outputs..where to start with this one?

The variables in the data set are: Event, EventType, FName, LName, Age, Gender, Score. I am trying to create a report that gives me the Lowest 5 scores per event/event type per each Age(18-65) per Gender. For example, I want the 5 lowest scores…
Jax
  • 27
  • 6
0
votes
1 answer

How to read in a time mm:ss.ss format into sas?

I am having trouble reading in one particular column of data. The raw text file column I am having trouble with looks like this: 55.49 1:23.57 32.22 5:38.43 12:52.17 25.13 The form is minute minute : second second ms ms. this particular data…
Jax
  • 27
  • 6
0
votes
1 answer

Matching observations based on similarity of categorical variables

I was wondering, if someone has a good way how to match two observations based on categorical (non-ordinal) variables. The exercise I am working on is matching mentees with mentors based on interests and other characteristics that are (non-ordinal…
Phill
  • 525
  • 6
  • 15
0
votes
2 answers

SAS Data step - In current dataset, loop through another dataset to get value

I have 2 datasets like this Dataset 1: From To Period 01/1/2000 20/1/2000 1 21/1/2000 14/2/2000 2 15/2/2000 31/3/2000 3 Dataset 2: Date 15/1/2000 13/2/2000 20/3/2000 And the desired result would be like this: Date …
johnpham
  • 3
  • 2
0
votes
2 answers

How can I write a DATA step that will drop all variables from the input dataset except the ones that I explicitly define within the dataset?

I want to generate a new SAS dataset using table foo as the input and one-to-one correspondence with records in the output dataset bar. I wand to drop variables from foo by default but I also require all of the fields of foo be available (to derive…
JustinJDavies
  • 2,663
  • 4
  • 30
  • 52
0
votes
4 answers

Dynamically create new variable in SAS dataset using an existing variable

I have a SAS dataset: +-------+-------+-------+-------+ | var_1 | var_2 | var_3 | index | +-------+-------+-------+-------+ | 1 | 10 | 100 | 2 | | 2 | 20 | 200 | 1 | | 3 | 30 | 300 | 3…
0
votes
2 answers

SAS - Data Step using Retain?

I have the following data... acct seq start end 1111 A 01/01/2014 01/31/2014 1111 A 02/01/2014 02/28/2014 I need to exclude records where the account has a start date that is 1 day after the end date. So…
user2941280
  • 285
  • 3
  • 9
  • 16
0
votes
1 answer

SAS: Data Step. By Processing

How can I aggregate the following sample data to give customer-level calculations? I'm using a data step with 'by processing', but I'm not sure whether or not I should break this up into two data steps or not. I need to extract the first type,…
user2146441
  • 220
  • 1
  • 19
  • 43
0
votes
4 answers

replicating a sql function in sas datastep

Hi another quick question in proc sql we have on which is used for conditional join is there something similar for sas data step for example proc sql; .... data1 left join data2 on first
user3135774
0
votes
1 answer

Simple SAS calculation

I have a data set with three columns: Names, ColA and ColB. There's a number of rows for each name, and for each name I need to subtract B from A, and make a new column get the remaining value of the differece between A and B: Names ColA ColB …
NHansen
  • 101
  • 2
  • 8
0
votes
3 answers

Creating a single record from multiple records in SAS

I have a SAS Data set called coaches_assistants with the following structure. There are always only two records per TeamID. TeamID Team_City CoachCode 123 Durham Head_242 123 Durham Assistant_876 124 London …
Clay
  • 2,949
  • 3
  • 38
  • 54
0
votes
2 answers

SAS - Select from multiple records with same id but different status

Sorry for the misleading (if there is) question title, as I don't know how to express what I need in 1 question. I have a dataset as below: UserId Order Status 1 1 completed 1 2 completed 1 3 …
Luke Henz
  • 137
  • 3
  • 5
  • 12