BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

Hello everyone! I will be very grateful if you help solve the problem.
I have two macro variables.
They look like this:

olgazabelinasas_0-1589545599679.png

I want to create two new macro variables that should look exactly like this:

'29JAN16:11:07:33'dt and '29JAN16:14:21:01'dt 

Is it possible? and if yes, please give the code

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Hi @olgazabelinasas 

A slight modification to your code with %unquote to will work for the macro processor to function properly


where t1.t_start<=%unquote(&data_s);

albeit the bigger picture or purpose seems a little misleading

View solution in original post

15 REPLIES 15
novinosrin
Tourmaline | Level 20

HI @olgazabelinasas  Not sure if I am missing some puzzle here. Isn't this supposed to be as simple as



%let date_start=29JAN16:11:07:33;

%let date_start_new=%bquote('&date_start'dt);

%put &=date_start_new;

The same for the date_end. I am lazy to type

olgazabelinasas
SAS Employee
sorry, it is not work 😞
novinosrin
Tourmaline | Level 20

what does not work?

 

Here is the log:

822  %let date_start=29JAN16:11:07:33;
823
824  %let date_start_new=%bquote('&date_start'dt);
825
826  %put &=date_start_new;
DATE_START_NEW='29JAN16:11:07:33'dt
PaigeMiller
Diamond | Level 26

I want to create two new macro variables that should look exactly like this:

'29JAN16:11:07:33'dt and '29JAN16:14:21:01'dt 

Macro variables, in general, should not be formatted. They should be numbers, not human readable text strings like above.

 

sorry, it is not work 

 

Well, it should work. Show us what you did, and show us the LOG from SAS (the entire log for this part of your code, including the code, the WARNINGs, and the ERRORs), and explain what did work.

 

 

--
Paige Miller
olgazabelinasas
SAS Employee

@PaigeMiller 

So, at first

olgazabelinasas_5-1589547536883.png

 

 

then

  • olgazabelinasas_1-1589547361940.png

 

and i just want to see something like this

 

olgazabelinasas_3-1589547493838.png

 

 

PaigeMiller
Diamond | Level 26

We need to see the ENTIRE log of  this sequence where you create a macro variable and then try to use it. We do not want you to chop parts out and only show us selected parts.

 

While I can't tell what the error is until I see the entire log, again I repeat that your macro variables should not be formatted. In this case, and any other cases where you compare a SAS date/time or date variable to a macro variable, formatting the macro variable does not help, and often causes the program to fail.

 

For future reference, we don't like to see code or log as screen captures.

 

When you signed up for the SAS communities, you should have received an e-mail stressing the importance of providing code in a "code box" which is the running man icon, and providing the log in a "code box" which is the </> icon. Please follow these guidelines.

--
Paige Miller
novinosrin
Tourmaline | Level 20

Hi @olgazabelinasas 

A slight modification to your code with %unquote to will work for the macro processor to function properly


where t1.t_start<=%unquote(&data_s);

albeit the bigger picture or purpose seems a little misleading

olgazabelinasas
SAS Employee
Thank you!!!
Tom
Super User Tom
Super User

I have a couple of questions.

First it is not clear how you generated those photographs from MACRO variables. You don't normally browse macro variables in a tabular presentation like that.  Can you just use %PUT to write the values to the log and copy the text from the log (don't take a picture of the text).

Do you really want single quotes? It would be easier to generate using double quotes since single quotes suppress macro triggers.

%put "&date_start"dt "&date_end"dt ;

 

ballardw
Super User

@Tom wrote:

I have a couple of questions.

First it is not clear how you generated those photographs from MACRO variables. You don't normally browse macro variables in a tabular presentation like that.


Maybe some use of the SASHELP.VMACRO view or the corresponding Dictionary table? Though I agree that looks somewhat suspicious.

Tom
Super User Tom
Super User

Are those dates from 2016 or 1916?  Do not use 2 digit years. 

 

Note there is a "feature" in the DATETIME format such that to get the 18 character string in style DDMONYYYY:HH:MM:SS with 4 digits for the year you must use a width of 19 in the format specification.  DATETIME19.  If you use DATETIME18 you get just the 16 character string with only two digits for year like in your example.

yabwon
Onyx | Level 15

Hi,

since you are using it in Proc SQL you can do it like this:

 

%let date_start=29JAN16:11:07:33;

%let date_start_new="&date_start."dt;

Bart 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 15 replies
  • 1485 views
  • 6 likes
  • 8 in conversation