BookmarkSubscribeRSS Feed
Fai
Calcite | Level 5 Fai
Calcite | Level 5
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.
3 REPLIES 3
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
deleted_user
Not applicable
"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.
Fai
Calcite | Level 5 Fai
Calcite | Level 5
Thanks! Got it working now.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 689 views
  • 0 likes
  • 3 in conversation