BookmarkSubscribeRSS Feed
HeatherNewton
Quartz | Level 8

what would I get for 

call symput("E_date", Feb21||" to "|| Jan22);

 

I tried but not getting the dates

6 REPLIES 6
SASKiwi
PROC Star

Either of these will work:

data _null_;
call symput("E_date", "Feb21 to Jan22");
run;

%let E_date = Feb21 to Jan22;
ballardw
Super User

"Not working" or similar without details is awful vague.

Are there errors in the log?: Post the code and log in a code box opened with the "<>" to maintain formatting of error messages.

No output? Post any log in a code box.

Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the "</>" icon or attached as text to show exactly what you have and that we can test code against.

 

Unless you have a variable named Feb21 I would expect that code to get notes such as this:

121  data example;
122     call symput("E_date", Feb21||" to "|| Jan22);
123  run;

NOTE: Numeric values have been converted to character values at the places given by:
      (Line):(Column).
      122:26   122:42
NOTE: Variable Feb21 is uninitialized.
NOTE: Variable Jan22 is uninitialized.
NOTE: The data set WORK.EXAMPLE has 1 obser

If you run my example above you will see that the data set now has two variables, with missing values, named Feb21 and Jan22 because the way you used them as variables in the concatenation attempt.

If they were variables with date values as in this example it still will likely fail to produce desired result. 

data example;
   feb21 = '03FEb2021'd;
   jan22 = '18Jan2022'd;
   format feb21 jan22 date9.;
   call symputx("E_date", Feb21||" to "|| Jan22);
run;

%put macro variable E_date is: &e_date. ;

Produces a result of :

macro variable E_date is: 22314 to        22663

because you did not provide any rules for displaying the variable as date text so Call symputx (newer version of call symput) uses a default format convert the numeric date value to text. That default is a best12 and right justifies the output. The reason there aren't more spaces in front of the 22314 is because symputx will try to remove leading and trailing blanks.

So with an actual example of what you expect perhaps:

140  data example;
141     feb21 = '03FEb2021'd;
142     jan22 = '18Jan2022'd;
143     format feb21 jan22 date9.;
144     call symputx("E_date",cat(put(Feb21,date9.)," to ",put(Jan22,date9.)));
145  run;

NOTE: The data set WORK.EXAMPLE has 1 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds


146
147  %put macro variable E_date is: &e_date. ;
macro variable E_date is: 03FEB2021 to 18JAN2022

WAY too often the automatic conversions to text of numeric values will result in problems. So take control of such.

 

Provide actual example of the input data, the result you expect and the result you are getting (if any) or a description of what doesn't happen. And the LOG.

 

 

 

HeatherNewton
Quartz | Level 8

HeatherNewton_1-1646373517290.png

the above is the result and it doesnt look right..

ballardw
Super User

@HeatherNewton wrote:

HeatherNewton_1-1646373517290.png

the above is the result and it doesnt look right..


Did you run the first example code? That is the output from my code because it is incorrect (most likely). If that is output from your code, then that means my example and yours are the same with the same incorrect code: using what is expected to be text in a place that it gets treated as a variable name.

 

Again, SHOW YOUR LOG. Copy the text from the log for something you run that generates "odd" or "wrong results". Then on the forum open a text box using the </> that appears above the message window and paste the text.

 

Please show your input and what you expect the output to look like.

Tom
Super User Tom
Super User

That cannot be the result of the code you posted.  That looks like the screen shot of someone browsing a dataset or perhaps some report.  Your code was just creating a macro variable.  But you only provided one statement.  You could not run this statement by itself.

call symput("E_date", Feb21||" to "|| Jan22);

You have to use that statement in a data step.

So what is the rest of the data step?

Do you actually have variables named FEB21 and JAN22?  From your photograph of the screen it looks like perhaps you didn't.

 

What did you want to put into the macro variable?

Kurt_Bremser
Super User

@HeatherNewton wrote:

what would I get for 

call symput("E_date", Feb21||" to "|| Jan22);

 

I tried but not getting the dates


This statement tries to concatenate the contents of variable feb21, the text " to " and the contents of variable jan22 into a macro variable called e_date.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 6 replies
  • 452 views
  • 0 likes
  • 5 in conversation