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

use a character date string as a date in data step

I have the following two macro variables: %let start_date = 29MAY2014; %let end_date = 15JUL2014; I would like to create a dataset which is a series of dates between these (inclusive.) I cannot change the input format of the macro variables…
datavoredan
  • 3,536
  • 9
  • 32
  • 48
0
votes
1 answer

sas execute a macro for each instance in a data step

I have a macro which inserts data into a table over a set of given time-frame. It loops through a series of from-to dates (which are stored in a dataset) and runs the macro with a proc sql insert statement. When checking the data at the end of all…
datavoredan
  • 3,536
  • 9
  • 32
  • 48
0
votes
1 answer

use a variable as a macro variable data step

I'm looking for a way to use a normal variable value as a macro variable in a data step. For example I have macro variable &statesList_Syphilis = AAA and another macro variable &statesList_Giardia = BBB And in a data step I have a variable Germ wich…
stallingOne
  • 3,633
  • 3
  • 41
  • 63
0
votes
1 answer

SAS in data step reshape a long data into wide with categorical variable

In SAS, a dataset I have is as follows. id A 1 2 1 3 2 1 3 1 3 2 ID is given to each individual and A is a categorical variable which takes 1, 2 or 3. I want to get the data with one observation per each individual separating…
Sue
  • 159
  • 1
  • 1
  • 6
0
votes
1 answer

Getting error while running SAS code

I'm getting an error while running the below code. &CNT is 50 and &vars has column names in it. Each column as some values from 1 to 100. I want to select each column and check the below criteria (%if statement), creating a new variable and…
0
votes
2 answers

SAS - Comparing observations within a group to pick values

I have 4 columns in my SAS dataset as shown in first image below. I need to compare the dates of consecutive rows by ID. For each ID, if Date2 occurs before the next row's Date1 for the same ID, then keep the Bill amount. If Date2 occurs after the…
Keneni
  • 705
  • 5
  • 12
0
votes
2 answers

Number of specific transactions in the last 5 trns

I would like to write sas code (proc-sql). The question is how to create variable VP_Trans (in the table below). The table below is referring to the customers transactions within some period. I would like to calculate how many VP transactions the…
Vendula
  • 29
  • 3
0
votes
2 answers

SAS Counting Occurrences based on multiple layers within set time period

I am trying to count occurrences where the same person was billed for an item, four or more times, by the same place within 30 days of each instance. For example, input would look something like: person service place date A x …
Brad
  • 85
  • 12
0
votes
0 answers

SAS: looping through table, performing count operation

SAS Beginner here. I have a table counting the number of patents an inventor makes across their career. ID | Year | Patents 1 1990 1 1 1991 0 1 1992 2 1 1993 0 1 1994 1 2 1975 1 2 1976 0 ... ... ... I want to…
frango_mints
  • 59
  • 1
  • 5
0
votes
1 answer

If else sas data step

I need to write the logic If y=1 then y=1; else y=y+x and z=5; Everything is normal but the second part of statement (and x=5) does not working.
0
votes
1 answer

Stalled data step in SAS

I am a novice SAS user and am trying to run a data step on a data set with 198 rows and 1611 columns. I don't think I am doing anything particularly elaborate in the data step, but it never completes it. I would really appreciate if someone could…
vokey588
  • 203
  • 1
  • 3
  • 9
0
votes
1 answer

If then output not working in UNIX SAS

Piece of code on Unix Server is not working, but works on PC SAS. When executed in UNIX SAS, the output datasets pc_pf_yes_1 and pc_pf_no_1 both have 0 observations, but no error is observed. In PC SAS, the code works fine and populates the datasets…
Lisle
  • 1,620
  • 2
  • 16
  • 22
0
votes
1 answer

SAS: macro procedure error in data step

I cannot find the solution to this error. I tried usign %eval, %sysfunc, and %sysevalf, with no success. What is needed to correctly evaluate the "&set" in the macro? %macro set_istituzionale(set=, varout=); %if &set/100 = 1 %then &varout =…
Giuseppe
  • 518
  • 10
  • 22
0
votes
1 answer

SAS Set two unequal data sets together horizontally, copy down smaller fille

Have two datasets, one one row, the other 100 rows. I want to set them together horizontally (not merge) and copy down the one row to all 100 rows. Right now I make a loop to copy down the rows of the smaller dataset, however its not very efficient…
aky
  • 11
  • 1
0
votes
0 answers

Error importing xlsx into sas creates trailing 9's

I have an Excel xlsx file with many worksheets, so I used an macro to import into SAS. %macro import (outname,sheetname); proc import datafile="C:\testing.xlsx" out= &outname dbms=xlsx replace; sheet="&sheetname"; run; proc contents data=&outname…
btiger
  • 35
  • 5