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: Return to previous observation in SAS Data Step possible?

I asked this question on RunSubmit too, since SAS Q&A community seems a bit scattered. If this is not appreciated, please let me know. Is it possible in a data step to return to a previous/certain observation and go from there further through the…
Yoh
  • 678
  • 1
  • 10
  • 18
2
votes
2 answers

SAS variable concatenation through data step

I am looking for a way to create a string variable containing certain values of the dataset while going through the data step. Example data set work.test: AddToStringYN Value Y One Y Two N Three Y…
Yoh
  • 678
  • 1
  • 10
  • 18
2
votes
5 answers

SAS - Row by row Comparison within different ID Variables of Same Dataset and delete ALL Duplicates

I need some help in trying to execute a comparison of rows within different ID variable groups, all in a single dataset. That is, if there is any duplicate observation within two or more ID groups, then I'd like to delete the observation…
2
votes
1 answer

In SAS, how to output at least one line in a data step when SET has zero records?

When reading a dataset which contains zero records the data step doesn't run any put statements. data test; set SASHELP.class end=eof; where 1=0; *output; if _N_=1 then put '['; put '"' name '",'; if eof then put name ']'; …
stallingOne
  • 3,633
  • 3
  • 41
  • 63
2
votes
2 answers

SAS if macro var is eq to string then filename

I have a basic question regarding the if/then structure and (over)writing a file. My &name var is set to name_b, but aa.js is always overwritten and bb.js. data _null_; if "&name" = "name_a" then do; filename cd_file '\\path\aa.js'; end; else if…
2
votes
3 answers

SAS Call execute output changes every time I run it

I’m running a macro with a call execute in a data step. What I want from my data step is the following: Take a table, add a new column for every existing column (via macro) and finally add a new column that is the sum of two others. I guess it is…
Zap
  • 147
  • 2
  • 9
2
votes
2 answers

Summing Multiple lags in SAS using LAG

I'm trying to make a data step that creates a column in my table that has the sum of ten, fifteen, twenty and fortyfive lagged variables. What I have below works, but it is not practicle to write this code for the twenty and fortyfive summed lags. …
Jarom
  • 1,067
  • 1
  • 14
  • 36
2
votes
1 answer

SAS Do Loop is Omitting Rows in Processing

I have the following code. I am trying to test a paragraph (descr) for a list of keywords (key_words). When I execute this code, the log reads in all the variables for the array, but will only test 2 of the 20,000 rows in the do loop (do i=1 to 100…
2
votes
2 answers

Copying/renaming multiple sas datasets based on macrovariables values

I have a macro variable &myfiles which contains a list of the names of four datasets. %put &myfiles; cpo.CDR_2016jun cpo.Cog_2016jun cpo.Mile_2016jun cpo.Path_2016jun Where cpo is a libname. I'm trying to create four new datasets with names from…
RAND
  • 281
  • 2
  • 14
2
votes
1 answer

create utf-8 text file from a sas datastep

I have this macro that creates a json file, but even though I have specified encoding='utf-8' bom I don't get an utf-8 file. %macro json4datatables_useformat(ds,path,file,charvars,numvars) / …
stallingOne
  • 3,633
  • 3
  • 41
  • 63
2
votes
3 answers

How to concatenate formatted values in SAS

I'm exporting data in JSON format with sas using this macro I made: %macro json4datatables(ds,path,file,charvars,numvars) / store source DES="json4datatables(ds,path,file,charvars,numvars)"; /* creates a json with no headers * a…
stallingOne
  • 3,633
  • 3
  • 41
  • 63
2
votes
3 answers

how to avoid spaces in put satement in SAS

I'm trying to write a json file from a data step. but my put statements always add unwanted spaces after variables. put ' {"year":' year ','; will create {"year":2013 , and put ' {"name":"' %trim(name) '", ' ; will create…
stallingOne
  • 3,633
  • 3
  • 41
  • 63
2
votes
1 answer

Character length in data step versus proc sql

Is it possible that creating a table with SAS proc sql will truncate a character variable at 255 characters? Does it have to do with the library engine type? I'm using a PCFILES libname like this (note the dbmax_text option): libname mylib PCFILES…
Matt Moehr
  • 123
  • 2
  • 10
2
votes
2 answers

How to Create an Embedded Hyperlink in a SAS Data Step

The case is: The target URL is for example "https://stackoverflow.com/". I have a data set with Ids. If I put "https://stackoverflow.com/"+"ID" it is the final hyperlink, which leads to the final webpage. How to create the list id Hyperlinks…
2
votes
2 answers

Open code statement recursion detected during exporting a file

I try to export a file in SAS but I get "Open code statement recursion detected." error. Since I export more than one files depending on date I define as a macro variable based on the prompt date, I want to name my file to be exported with this…
Jonsi Billups
  • 133
  • 1
  • 3
  • 15
1
2
3
16 17