DATA Step, Macro, Functions and more

Converting to TIME., Performing Functions, then PUTing into TXT file

Reply
New Contributor Fai
New Contributor
Posts: 2

Converting to TIME., Performing Functions, then PUTing into TXT file

Hi, I’m trying to convert two character variables into time variables (HHMM) then find the difference between the two variables and put that into a comma delimited text file. I have been able to get variables from my SAS database to go into the text file, but not the variables that I create myself. Here is my code and error message. How can I create a new variable (length) that shows the difference between the two other variables, and get it into the text file? Thanks.

libname r1 '/stuff/things/r1';
libname r2 '/stuff/things/r2';
libname r3 '/stuff/things/r3';
libname r4 '/stuff/things/r4';


data _null_;
begin = input(START, TIME4.);
finish = input(END, TIME4.);
length = finish - begin;

file '/location/place/port.txt' dlm=',';
set r1.ld(keep= START END length )
r2.ld(keep= START END length )
r3.ld(keep= START END length )
r4.ld(keep= START END length );


put START END length ;
run;


ERROR: The variable length in the DROP, KEEP, or RENAME list has never been referenced.
Super Contributor
Super Contributor
Posts: 3,174

Re: Converting to TIME., Performing Functions, then PUTing into TXT file

It's unclear how you are introducing the START and END variables to your DATA step - you would either need an INPUT statement if reading up the values from an external file or you need to have your SET statement coded ahead of the SAS assignment statement where START and END are referenced.

Using the PUTLOG _ALL_; statement for DATA step program diagnosis may help you understand better what's going on at various points during the DATA step execution.

Scott Barry
SBBWorks, Inc.
N/A
Posts: 0

Re: Converting to TIME., Performing Functions, then PUTing into TXT file

"length" is a reserved name in SAS and shouldnot/cannot be used as a SAS variable name.
Same for "end"

SAS is complaining about "length" used in your keep option statements.

there are many other problems with your code as well.
New Contributor Fai
New Contributor
Posts: 2

Re: Converting to TIME., Performing Functions, then PUTing into TXT file

Thanks! Got it working now.
Ask a Question
Discussion stats
  • 3 replies
  • 155 views
  • 0 likes
  • 3 in conversation