BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
ramgouveia
Obsidian | Level 7

I have the following code:

 

%let dt = &systime;
%let dhour = substr(&dt.,1,2);
%let dminute = substr(&dt.,4,2);
%put NOTE : system data is &dhour. &dminute. ;

which produced the following result:

NOTE : system data is substr(10:44,1,2) substr(10:44,4,2)

 

The result I want is:

NOTE : system data is 10 44

 

Can you help me to correct the code?

1 ACCEPTED SOLUTION

Accepted Solutions
svh
Lapis Lazuli | Level 10 svh
Lapis Lazuli | Level 10
Since the SUBSTR() function takes a macro variable as an argument, use %SUBSTR().

View solution in original post

3 REPLIES 3
svh
Lapis Lazuli | Level 10 svh
Lapis Lazuli | Level 10
Since the SUBSTR() function takes a macro variable as an argument, use %SUBSTR().
ramgouveia
Obsidian | Level 7

Thank you @svh 

Tom
Super User Tom
Super User

The macro processor is just a text pre-processor.  It looks for the & and % triggers to see where it needs to take action.

In your code you are only use the & trigger.  So the string substr is not modified by the macro processor.

 

You probably want to use the macro function %SUBSTR() or  the macro function %SCAN() instead.

555  %let dt=&systime;
556  %let dhour=%substr(&dt,1,2);
557  %let dminute=%substr(&dt,4,2);
558  %put &=systime &=dt &=dhour &=dminute;
SYSTIME=09:44 DT=09:44 DHOUR=09 DMINUTE=44

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 392 views
  • 2 likes
  • 3 in conversation