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

How to suppress infinite loop note when using "IF 0 THEN SET"

To 'copy' the PDV structure of a data set, it has been advised to "reference a data set at compile time" using if 0 then set For example, data toBeCopied; length var1 $ 4. var2 $ 4. ; input var1 $ var2 $; datalines; this …
Lorem Ipsum
  • 4,020
  • 4
  • 41
  • 67
1
vote
1 answer

Using macro variables in datastep arguments

I'm trying to write tiny programm with parameters to backup datasets (name+date+time) in Enterprise Guide. Here's code: data &WhatLib..&WhatTable%str(_)&SYSDATE.%sysfunc(tranwrd(%str(&SYSTIME.),:,_)) ; set &WhatLib..&WhatTable…
Sanek Zhitnik
  • 716
  • 1
  • 10
  • 25
1
vote
3 answers

SAS How to concatenate strings several times in the same variable during a data step

A very basic question. How come I cannot change a variable in a datastep like this? data want; aaaaa='['; aaaaa=cats(aaaaa,'hello'); aaaaa=cats(aaaaa,']'); put aaaaa; run; aaaaa will be equal to '[' , I expect '[hello]' I need to…
stallingOne
  • 3,633
  • 3
  • 41
  • 63
1
vote
1 answer

in SAS, is it possible to declare 2 hash tables in the same data step?

I'm able to declare 1 hash table like this: data DALY1; * set lengths ; length Germ $10 Category1 $50 Category2 $50 AgeGroupDALY $10 Gender $2 value 8; * make link to hash table ; if _n_=1 then do; declare hash…
stallingOne
  • 3,633
  • 3
  • 41
  • 63
1
vote
1 answer

Exported xlsx-file corrupted when sent via data step

I have exported sas-dataset, copied to my computer using WinSCP and opened it succesfully. However, when I sent the file using data step, the file is corrupted. I click the file in Outlook and Excel says "The workbook cannot be opened or repaired…
1
vote
2 answers

Convert Proc Sql Exists Query to Data Step

I have this proc sql query in my current code. Unfortunately, I'm dealing with over 10 million records, so it takes hours to run. I've been trying to convert it to a data step, thinking it would run much quicker. However, I can't seem to get the…
UncleCross
  • 33
  • 3
1
vote
2 answers

Reading from input with double trailing @@

Input: G0894 x 1 x 3 x 1 k 1 C4458 x 1 k 5 C9057 x 7 x 4 x 4 x 3 x 5 Desired output: G0894 x 1 G0894 x 3 G0894 x 1 G0894 k 1 C4458 x 1 C4458 k 5 C9057 x 7 C9057 x 4 C9057 x 4 C9057 x 3 C9057 x 5 This is what I came up with: data want; infile…
matt-pielat
  • 1,659
  • 3
  • 20
  • 33
1
vote
3 answers

update statement in data step

In the database we have email address dataset as following. Please notice that there are two observations for id 1003 data Email; input id$ email $20.; datalines; 1001 1001@gmail.com 1002 1002@gmail.com 1003 1003@gmail.com 1003…
useR
  • 3,062
  • 10
  • 51
  • 66
1
vote
2 answers

What is a by statement really doing in a sas data step?

Okay this seems like a very simple thing, but I can't explain what a "by statement" in a sas datastep is really doing. I know when I need to use it, but I am not sure what it is doing. In the example below I understand what the virtual sas…
invoketheshell
  • 3,819
  • 2
  • 20
  • 35
1
vote
1 answer

How to create macro variable from a column of dataset using data step not SQL?

We can make macro variables via the SAS SQL Procedure, using the syntax select var into :mvar But I wonder if there's same way in data step. I have a dataset. A B === === a1 b1 a2 b2 a3 b3 I can make a macro variable called MA with the…
raccoonjin
  • 217
  • 1
  • 5
  • 12
1
vote
1 answer

Insert a variable number of rows

Currently, my macro is running to insert a constant number of rows: %MACRO ADD_PERIOD; %DO P = 1 %TO 39; Would I be able to modify this macro or create a new macro to run this, not 39 times, but replace the number of loops with a variable I have…
Young
  • 11
  • 3
1
vote
2 answers

Automated grouping in SAS with minimizing variance within group

So I tried to build the automated grouping. The goal is to select the grouping setting that has the lowest variance. In other word, I want to find x and y for the following, x,y are natural number, GROUP 1: 1997 - x GROUP 2: x+1 - y GROUP 3: y+1 -…
devon
  • 321
  • 2
  • 10
1
vote
1 answer

Use array variables in subsetting IF without specifying number of array variables

In SAS, I have a few columns of dollar values and several other columns. I don't care about a row of data if it has 0 values for all dollar values and I don't want these rows in the final data. The columns that are dollar values are already in an…
GeoffDS
  • 1,221
  • 5
  • 19
  • 31
1
vote
1 answer

Using PROC SORT and DATA _NULL_ to produce report with SAS

(Note: this is a homework assignment for which I have the correct answer, but I am unsatisfied with the results.) A little context with regards to the data. Information on each of four drugs was recorded for a patient's coming in for a clinic visit:…
k6adams
  • 406
  • 1
  • 3
  • 12
1
vote
1 answer

Attaching a variable based on source table in DATA STEP

I am stacking together several data snapshots that exist in separate tables. The following code iterates over a large number of datestamped snapshots and extracts key-value pairs. Is there a simple way to attach the value of the macro variable…
JustinJDavies
  • 2,663
  • 4
  • 30
  • 52