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
2 answers

SAS: Utilizing macro variables as numbers in data step

I am touching up some SAS code I wrote and found a chunk of code I wish to execute more effectively. I have a time-series data set called 'Forecasts' which just consists of date and the 'Forecast' variable for a given date. I wrote a simple block of…
Josh Kraushaar
  • 369
  • 5
  • 17
0
votes
1 answer

SAS: Spliting data groups into its own rows

I'm new to SAS and found myself having to use it for my new job. So this is a basic question. I have a table which looks like this: COMPANY | Employee --------|---------- COMP1 | @,@,@,@ COMP2 | @ COMP3 | @,@ ... Every @ is an email adress -…
0
votes
4 answers

SAS/SQL - find 3 or more occurences within a given timeframe

I have hundreds of thousands of rows of data (like the example below) which consists of account number and the dates of calls that were placed. I need to find all accounts where there were 3 or more calls placed within a 7 day period. So, for the…
UncleCross
  • 33
  • 3
0
votes
3 answers

Select many columns and other non-continuous columns to find duplicate?

I have a dataset with many columns like this: ID Indicator Name C1 C2 C3....C90 A 0001 Black 0 1 1.....0 B 0001 Blue 1 0 0.....1 B 0002 Blue 1 0 0.....1 Some of the IDs are duplicates because the indicator is…
PinkyL
  • 341
  • 1
  • 8
  • 19
0
votes
2 answers

SAS: Get number of variables in current data step

I need a way to dynamically return the number of variables in the current data step. Using SAS NOTE 24671: Dynamically determining the number of observations and variables in a SAS data set, I have come up with the following macro. %macro…
Lorem Ipsum
  • 4,020
  • 4
  • 41
  • 67
0
votes
2 answers

Is there a way to compute percentiles without storing values from a loop, in SAS?

Is there a way to compute the 5th and 95th percentiles without storing all the values from a loop? %let it=10000; data test; length arrayStore$32767; arrayStore=''; sum=0; min=99999; max=-99999; do i=1 to ⁢ …
stallingOne
  • 3,633
  • 3
  • 41
  • 63
0
votes
3 answers

How to resolve macro variable in a loop in SAS

I am trying to figure out how to call a macro variable in a loop within a data step in SAS, but I am lost; so I have 14 macro variables and I have to compare each of them to the entries of a vector. I tried: data work.calendrier; set…
Stefka
  • 21
  • 1
0
votes
1 answer

SAS Data Step not incrementing as expected

This is the code I have written. It consists of 3 Data Steps. The first 2 work perfectly, but the last doesn't do anything and I can't work out why. Any help would be very much appreciated data A.OCT_DEDUPE_LEVEL1; set A.OCT_NOMANLOGOFFERR; …
Taylrl
  • 3,601
  • 6
  • 33
  • 44
0
votes
2 answers

SAS Index on Array

I am trying to search for a keyword in a description field (descr) and if it is there define that field as a match (what keyword it matches on is not important). I am having an issue where the do loop is going through all entries of the array and .…
0
votes
2 answers

Can you force a by variable to numeric in a merge efficiently?

I have a bunch of SAS data sets with a seq number that I want to merge by. Unfortunately in some data sets the seq is numeric and in others it's character. I get the following error: ERROR: Variable seq has been defined as both character and…
invoketheshell
  • 3,819
  • 2
  • 20
  • 35
0
votes
3 answers

sum over rows split between two columns

my data looks like this and I cant figure out how to obtain the column "want". I've tried various combinations of retain, lag and sum functions with no success unfortunately. month quantity1 quantity2 want 1 a x …
DURAL
  • 37
  • 5
0
votes
3 answers

First and last function sas

I have some data which looks like this data example1; input Activity $ logflag; Activity1 1 Activity2 1 Activity3 1 Activity4 1 Activity1 2 Activity2 2 Activity3 2 Activity1 3 Activity2 3 Activity3 3 …
Taylrl
  • 3,601
  • 6
  • 33
  • 44
0
votes
1 answer

Replace a string with a line feed in SAS

I want to read a file and find the word “the” and introduce a line feed. i.e. find and replace the text ‘the’ to ‘/nthe’ Can you please help? /*input.txt*/ Many a slip between the cup and the lip. /*Required output*/ Many a slip…
AKS
  • 184
  • 2
  • 18
0
votes
1 answer

SAS Data step free format issue

I would like to include a line feed before the keyword 'data-base-url' only when it doesnt have one. Input File USERNAME 1
AKS
  • 184
  • 2
  • 18
0
votes
1 answer

SAS DS2 put statement output to a file

I have a SAS DS2 program which prints the output in the screen from a data step as below, I would like to channel the output to a file. AFAIK, 'file' is a missing feature in DS2 since DS2 currently reads and writes to tables, can someone please let…
AKS
  • 184
  • 2
  • 18