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

Where can I find documentation for the Select/When/Otherwise statement?

I love using the Select/When/Otherwise statement in the data step, but my code always needs debugged before it will run properly. I never can remember the exact syntax required and SAS doesn't have very good documentation for it. (I actually can't…
Michael Richardson
  • 4,213
  • 2
  • 31
  • 48
-1
votes
1 answer

SAS code - sum of last N rows for every row

I have a dataset like this for each…
Deniz
  • 53
  • 7
-1
votes
1 answer

How to create binary column that compares a value to the total average of the same column such that if nb > average=1 & nb < average=0

I'm working on an assignment & not allowed to use PROC SQL & must use DATA STEP or other PROCs. I have a dataset (Table A), & I'm trying to calculate a few things at the same time and I'm not any closer to my answer after spending few hours on…
Earl
  • 3
  • 2
-1
votes
2 answers

How to convert date format from imported CSV to be able to merge data

I'm working on an assignment & not allowed to use PROC SQL. I imported data from two csv files & renamed columns at the same time (see code below) but when I tried to PROC APPEND the two tables, there's an issue with the date format. When I PROC…
Earl
  • 3
  • 2
-1
votes
1 answer

SAS: adding character variables in data step without setting the lenghth in advance

In a SAS data step, if one creates a character variable he has to be careful in choosing the right length in advance. The following data step returns a wrong result when var1=case2, since 'var2' is truncated to 2 characters and is equal to 'ab',…
Giuseppe
  • 518
  • 10
  • 22
-1
votes
1 answer

Compare SAS Data Step and PROC SQL using Concatenate function

Following is the Data Step I am trying to work on. I am a beginner in SAS. I want to compare the performance of SAS DATA Step and PROC SQL using concatenation. I tried to do it but i am not getting the same output for the DATA step and proc SQL.…
-1
votes
1 answer

Using a set statement to select many files with a pattern

I am trying to load in a large number of data sets that have a similar pattern to their naming in a set statement ie data output; set &filenames. ; I have seen in other questions a method of creating a macro with all of the names using a proc…
student_t
  • 243
  • 2
  • 9
-1
votes
1 answer

Create new rows in SAS equal to the value of variable

I am trying to insert new rows for each id, the number of rows should be equal to the value of a certain variable. For example, say I have the variables ID and X1 which look like this: ID X1 A 3 B 1 C 5 Then I want the table…
-1
votes
1 answer

SAS: How can i output a table that shows the column name, max length, and defined length of that column?

In SAS I'm trying to figure out how to get output (results or actual dataset) that show me the column name, var length, and max length (which would of course be repeated for each obs with that column name).
thepen
  • 1
-1
votes
4 answers

How can I extract the unique values of a variable and their counts in SAS

Suppose I have these data read into SAS: I would like to list each unique name and the number of months it appeared in the data above to give a data set like this: I have looked into PROC FREQ, but I think I need to do this in a DATA step, because…
-1
votes
1 answer

intervals of dates - summing

I have one table with dates: Table1 Date_start Date_end 01JUL1997 01JUL1998 01JUL1998 01APR1999 01APR1999 01OCT2000 01OCT2000 01JUL2001 and second table where with date and number : Table2 Date_of_pay Cash 01DEC1999:00:00:00 …
mical
  • 3
  • 1
-1
votes
3 answers

Calculate mean and std of a variable, in a datastep in SAS

I have a dataset where observations is student and then I have a variable for their test score. I need to standardize these scores like this : newscore = (oldscore - mean of all scores) / std of all scores So that I am thinking is using a Data Step…
Storm
  • 1
  • 1
  • 4
-1
votes
1 answer

Where is the syntax error within this SAS view code?

data work.temp work.error / view = work.temp; infile rawdata; input Xa Xb Xc; if Xa=. then output work.errors; else output work.temp; run; It says there's a syntax error in the DATA statement, but I can't find where ...
dayaoyao
  • 120
  • 2
  • 9
-1
votes
3 answers

select unique combination in two overlap datasets

For example, in SAS, I have 5 IDs in dataset A(below left). There is a dataset B,(could potentially contain some A's IDs,below right).What I need is to find one unique combination( A is the primary outcome dataset) on A and B has same sex, age…
-1
votes
2 answers

SAS Programming - DATA Step - Text to SAS Data Set Parsing Issue

I am trying to create a SAS Data Set from a text file. The text file shows data in a format exactly like this: -HEADER HEADER HEADER -HEADER HEADER HEADER April SpringRace Male $$$$$$$$$$$$$$$$$$$$ Name Age State /these are titles in the text…
Jax
  • 27
  • 6
1 2 3
16
17