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
1
vote
1 answer

SAS DO Loop seems to skip records

In writing a very simple DATA step to start a new project, I ran across some strange behavior. The only difference between set1 and set2 is the use of the variable lagscore in the equation in set1 vs. dummy in the equation in set2. set1 produces…
TParrent
  • 13
  • 3
1
vote
1 answer

SAS - How to filter by max value from one column in a datastep

I have a yearly survey that I do some validations on. I only want to do the validations for the current year (max year in the column surveyYear). The survey comes every year so I want to have it automatised instead of writing the current year. So…
aef
  • 35
  • 8
1
vote
2 answers

create "pair key=value" file with SAS datastep

I have to create a file from a dataset that is JSON style but without CR between each variable. All variables have to be on the same line. I would like to have something like that : ID1 "key1"="value1" "key2"="value2" ..... Each key is a column of a…
chezleon
  • 29
  • 7
1
vote
2 answers

Resolution of Macro Variables in a Data Step

I'm having trouble getting If/Then statements to work correctly with my macro variables inside a datastep. I'm writing a macro to handle two different cases: calculating stat tests with no transformation, and then calculating stat tests after a…
Kevin.C
  • 309
  • 1
  • 2
  • 10
1
vote
1 answer

SAS: How do I add a value with brackets and quotes in a data step?

I want to create a table using a data step in SAS that contains the display format codes for SSRS. For example, I have some codes like this '#,0;(#,0)' but I am getting errors when I try to assign this value in a data step. I also tried to put it…
Airbum88
  • 19
  • 1
  • 9
1
vote
1 answer

SAS: sort error (by variable not sorted properly)

This question is a follow up from another I had here SAS: Data step view -> error: by variable not sorted properly; I am opening a new question as the desired solution is slightly different: As I am looping through several input files, one of the…
eternity1
  • 651
  • 2
  • 15
  • 31
1
vote
2 answers

SAS: Data step view -> error: by variable not sorted properly

I am using a macro to loop through files based on names and extract data which works fine for the majority of the cases, however from time to time I experience ERROR: BY variables are not properly sorted on data set CQ.CQM_20141113. where…
eternity1
  • 651
  • 2
  • 15
  • 31
1
vote
4 answers

SAS include code into data step

I have dynamically create a myfile.sas with following content: and a = 0 and b = 0 Now I want to include this file into a data step: data y; set x; if 1=1 %include incl("myfile.sas") then selektion=0; else selektion=1; run; The…
zuluk
  • 1,557
  • 8
  • 29
  • 49
1
vote
2 answers

Keep trailing blank in string

I have the following temp dataset with 2 observations. The second observation contains a trailing blank.In the data _null_ step I read the value from the second observation with call symput. In the put statement the value is written to the log with…
zuluk
  • 1,557
  • 8
  • 29
  • 49
1
vote
1 answer

How do I put numbers right aligned?

How do I put numbers right aligned in a SAS data step? data _null_; num = 1; put num=6.0; num = 10; put num=6.0; num = 100; put num=6.0; run; This data step puts num=1 num=10 num=100 What I have wanted (and expected) was that it…
René Nyffenegger
  • 39,402
  • 33
  • 158
  • 293
1
vote
1 answer

SAS - Hive Data step delete issue

When we drop a managed table , Hive deletes the data in the table is my understanding. By default, SAS data step option DBCREATE_EXTERNAL is set to NO which means SAS data step using hive libraries like below creates a “managed table”. When using…
AKS
  • 184
  • 2
  • 18
1
vote
2 answers

Conditional IF statement with lagged values

I have the following dataset, structured as follows: DATE PERCENTAGE FLAG VALUE1 01JAN2017 0.21 1 1.50 04JAN2017 0.05 0 2.43 09JAN2017 0.06 1 2.21 24JAN2017 …
QuantumGorilla
  • 583
  • 2
  • 10
  • 25
1
vote
2 answers

Summing Multiple Columns By Date in SAS

I have data that looks like this in SAS; Date Type_1 Type_2 4/8/2015 21654.72 . 4/9/2015 34490.13 . 4/9/2015 32429 . 4/9/2015 . 24438.76 4/9/2015 . 54043.18 4/9/2015 . 58969.06 4/9/2015 . …
Jarom
  • 1,067
  • 1
  • 14
  • 36
1
vote
2 answers

Dropping variable based on sum of values in it using SAS

I wish to drop the columns in a SAS dataset which has a sum less than a particular value. Consider the case below. Column_A Pred_1 Pred_2 Pred_3 Pred_4 Pred_5 A 1 1 0 1 0 A 0 1 0 1 0 A …
1
vote
2 answers

Will Index file be updated after renaming the key variable in SAS?

According to Understanding SAS Indexes If you rename key variable in SAS, the simple index is renamed instead of being deleted. However, when I try this on my own, the index file will disappear after I rename the key variable, I wonder what is…
lleiou
  • 475
  • 7
  • 13