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

sas insert table into html email

Is it possible to loop through the records of a table to populate an html email without repeating the beginning and the end of the email? With this example I get a mail with 5 tables of 1 row (because WORK.MyEmailTable is table of 5 records and set…
stallingOne
  • 3,633
  • 3
  • 41
  • 63
2
votes
2 answers

SAS outputting results to the input dataset (same in and out dataset name)

I could not find information about this problem, or could not specify the question correctly. Let me ask the question with code: Is this operation data work.tmp; set work.tmp; * some changes to data here; run; or especially proc sort data =…
Matek
  • 641
  • 5
  • 16
2
votes
2 answers

How can I peform same datastep across many variables in SAS?

I have data that looks like this and has 500 variables with a target: var1 var2 var3 var4 ... var500 target The names of the variables are not sequential as above so I don't think I can use something like var1:var500. I want to loop through the…
invoketheshell
  • 3,819
  • 2
  • 20
  • 35
2
votes
3 answers

How to create this macro with conditions?

Sample input data: FirstName LastName Group Age LastVenue Position Jack Smith ULDA 25 TheaterA 1 Jesse James GODL 37 TheaterB 12 Jane Doe ULDA 29 TheaterA 3 Izzy…
Jax
  • 27
  • 6
2
votes
2 answers

SAS task. Need to pick records conditionally

I have been given a task to solve, I'm quite new to this programming language. When the flag is 0, I have to pick the next immediate record, provided the flag variable has three or more consecutive records with value 1. I have been going at it for…
Nimit_ZZ
  • 495
  • 4
  • 10
  • 21
2
votes
1 answer

difference between performance of proc copy and that of data step

Consider two scenarios of sales contains over 10M records, 50 bytes for one record: SCENARIO ONE: data STORE.sale; set work.sale; run; proc copy in = work out = STORE; select sale; run; SCENARIO TWO: data STORE.sale; set FACTORY.sale; run; proc…
Lovnlust
  • 1,507
  • 3
  • 29
  • 53
2
votes
2 answers

How to convert date value from day to Quarter in SAS

I have a data set like this: date 01JAN90 01APR90 01JUL90 01OCT90 01JAN91 01APR91 01JUL91 01OCT91 I want to convert the date value into date 1990Q1 1990Q2 1990Q3 1990Q4 1991Q1 1991Q2 1991Q3 1991Q4 How can I do it in SAS?
Elif Y
  • 251
  • 1
  • 4
  • 21
2
votes
1 answer

How do I place a tab character in a PUT statement within a DATA step?

How do I place a tab character in a PUT statement within a DATA step? I am using SAS to output a processing log : if first.ref then PUT 'PROCESSING: ' ref ; if InceptionDate > LossDate then do; if first.ref then PUT…
JustinJDavies
  • 2,663
  • 4
  • 30
  • 52
2
votes
4 answers

SAS - Data Step equivalent of Proc SQL

What would be the data step equivalent of this proc sql? proc sql; create table issues2 as( select request, area, sum(issue_count) as issue_count, sum(resolved_count) as resolved_count from issues1 group by…
user2941280
  • 285
  • 3
  • 9
  • 16
2
votes
1 answer

Input from File in Data Step without Left Trim

I have a variable length, quite ugly reporting file that I am trying to read into SAS. When reading file records, I am finding that spaces on are being automatically trimmed from the left side of the file. This is making it harder to compare the…
lfrandom
  • 1,013
  • 2
  • 10
  • 32
2
votes
2 answers

SAS Folder Path for Metadata tables

I'm wondering if anyone knows how to retrieve the sas folder path for metadata tables? I would like to list the folder path for each tables located on metadata. Example: Table FactPortfolio is under the following fodler structure in management…
user3270069
  • 31
  • 1
  • 4
2
votes
2 answers

How to calculate conditional cumulative sum

I have a dataset like the one below, and I am trying to take a running total of events 2 and 3, with a slight twist. I only want to count these events when the Event_1_dt is less than the date in the current record. I'm currently using a macro %do…
2
votes
1 answer

Read JSON file and save it in SAS dataset

I am trying to read data from JSON file and store the value in SAS dataset Here is my JSON file test.json [ { "id":1, "name":"Johnson, Smith and Jones Co.", "amount":345.33, "Remark":"Pays on time" }, { "id":2, …
goldenbutter
  • 575
  • 2
  • 12
  • 25
2
votes
3 answers

What does this if mean in a data step?

In this data step I do not understand what if last.y do... Could you tell me ? data stop2; set stop2; by x y z t; if last.y; /*WHAT DOES THIS DO ??*/ if t ne 999999 then t=t+1; else do; t=0; z=z+1; …
statquant
  • 13,672
  • 21
  • 91
  • 162
2
votes
2 answers

SAS DATA: How to remove observations that only occur once

In SAS, suppose I have a dataset named "person_groups". It has two variables, named "person" and "group". This dataset simply assigns each person to a group. How can I remove from this dataset all persons who have no one else in their group? In…
synaptik
  • 8,971
  • 16
  • 71
  • 98
1 2
3
16 17