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

counter variable not meant to reset

This is the follow up of another post I made before. Turns out that, when creating that "counter" variable I want to include a condition so if a variable called "outcome" takes value "out of time", the counter is 0, but it shouldnt reset the count…
amestrian
  • 546
  • 3
  • 12
0
votes
1 answer

SAS data step with BY variable on unsorted data

I'm executing SAS data step with by variable. I understand the output when the data is sorted by key (X in my case). However, when the data is unsorted, I get the following output: I'm using SAS ODA's AFRICA dataset from MAPS library which has…
Shradha
  • 2,232
  • 1
  • 14
  • 26
0
votes
2 answers

Group By Interpolation Based on the Previous Row

The goal is to add a new row whenever there is a gap between the date variable between two rows grouped by id. If the gap occurs, then duplicate a row that is first. However only the date feature should not be as the first row rather it should be…
Loncar
  • 125
  • 8
0
votes
1 answer

Create grid data in SAS using info from another dataset

I need to get a dataset of a uniform grid 20x20 using info from SASHELP.CARS so that x and y variables are obtained as follows: do y = min(weight) to max(weight) by (min(weight)+max(weight))/20; do x = min(horsepower) to max(horsepower) by…
adeline
  • 21
  • 4
0
votes
1 answer

search and replace not working in sas as expected

I am trying to replace the words from list1 to list2 (basically translating from one language to another), but the search and replace function is not working as expected. It only replaces a portion of thew string and not the complete. Am I doing…
Chug
  • 31
  • 6
0
votes
2 answers

Extract string after numerics in SAS

I need to extract the string after the numbers. Although the problem is that the number of digits at the front of the string is inconsistent. What I need is something similar like the Flash Fill in Excel. But I'll be doing it for 100K+ rows so Excel…
user3360708
  • 35
  • 1
  • 4
  • 9
0
votes
1 answer

Creating complex logic counter variables in SAS

I have to create complex (for me) counter variables in a dataset. I am trying to explain as clearly as possible. If anything unclear please let me know. Hope with your help I can achieve what I am expecting. I need to create three variables:…
Myurathan Kajendran
  • 647
  • 3
  • 8
  • 15
0
votes
1 answer

Flagging Lines Below HHMM Threshold SAS IF/THEN Data Statement

I have a dataset where I calculated the number of total hours it took to process a request in hours. A request should be completed in 72 hours, or else if an extension is requested a request should be completed in 408 hours (14 days plus 72…
0
votes
1 answer

Get a string of column names in sas when value is 1

This is the given dataset Ins_id Prod1 Prod2 Prod3 Prod4 1234 1 0 1 0 5678 0 0 1 0 91011 0 1 0 1 12131 1 1 0 1 I want to create a new column that displays all the column names when…
Chug
  • 31
  • 6
0
votes
1 answer

Creating table with cumulative values

I have table like first table on the picture. It's information about banks deals on the FX market on daily basis (buy minus sell). I would like to calculate cumulative results like on the second table. The number of banks and their names, also as…
0
votes
1 answer

Displaying 'NA' when it's an empty row in SAS

This is the given data Company_NO Hierarchy_1 Hierarchy_2 1234 Insurance A 1234 Insurance A 1234 Auto B 5678 Claims B 5678 Claims B 5678 New C In the above table, the column…
Chug
  • 31
  • 6
0
votes
1 answer

Grouping successes in SAS on multiple rows by ID where at least 1 success counts as a success

I'm working with a dataset of call logs and I need to summarize how many subscribers have been successfully contacted. Each row is one call, and if at least one call for a subscriber is a success, I need to set a variable that outputs "successful…
0
votes
3 answers

How to combine two columns in new rows in SAS?

I have a dataset as follows: variable level value ----------------------- Age_group 1 0.1 Age_group 2 0.3 Age_group 3 0.2 Age_group 4 0.5 Sex 1 0.9 0 0.6 I would like to reformat it to…
0
votes
1 answer

it is possible to convert subselect with max function into SAS datastep?

it is possible to convert code below from proc sql into sas datastep? proc sql; create table CAL_CHECK as select t1.DT_REP , t1.BANK_FLAG , (select MAX(t2.DT_REP) as LAST_BD_BANK_FLAG from CZ_LOOK.CZ_CALENDAR t2 where t2.DT_REP <…
Keliimek
  • 155
  • 1
  • 1
  • 10
0
votes
2 answers

SAS data step - dynamic select field from table

I have little problem with one case. Please look at table HAVE. And WANT. My process: get value from VAR, divide by 12, round up to the nearest whole number and put in WANT table, in RES field value from FIELD&"result of the action". How I can do…
DarkousPl
  • 85
  • 1
  • 10