BookmarkSubscribeRSS Feed
astha8882000
Obsidian | Level 7

I read this line of code somewhere, I understand that the variable 'Memo' is initialized  to the value 'Aug 16', what is the purpose of '@'?

 

Also, the user usually goes in and updates the date everyday. Instead of doing that, isn't turning that into a macro variable a better option?

 

%let Memo = %sysfunc(today());

2 REPLIES 2
ChrisHemedinger
Community Manager

I'm not familiar with that @ symbol in an assignment statement -- but it could be a piece of esoteric legacy that someone else could weigh in on.

 

The most common use of the @ symbol to control assignments is in the INPUT statement, using it to advance the input pointer to a specific part of the input stream.  In this example, the @ operator tells SAS to find the pattern "Memo" and then reads the value just beyond that point. 

 

data test;
  length date 8;
  informat date date9.;
  format date date9.;
  infile datalines;
  input @ "Memo" date;
datalines;
Here's the Memo 16Aug2017
Another Memo 16Nov2018
Final Memo 15Oct2014
;
run;

 

op.png

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
ballardw
Super User

@astha8882000 wrote:

I read this line of code somewhere, I understand that the variable 'Memo' is initialized  to the value 'Aug 16', what is the purpose of '@'?

 


Showing the entire code would be better since the '@' can play a number of different roles in reading data.

 


 

Also, the user usually goes in and updates the date everyday. Instead of doing that, isn't turning that into a macro variable a better option?

 

%let Memo = %sysfunc(today());


Since on 2 May 2018 the macro variable Memo received the value with that call of 21305, likely not the optimal solution.

You would have to use sufficient SAS functions to make the macro variable appear exactly as the value appears in your data set.

This might get you started:

Data _null_;
   str=catx(' ',put(today(),monname3.),day(today()));
   call symputx('memo',str);
run;

but may need tweeking if the day part of your search string should be Aug 01 instead of Aug 1.

 

Don't forget to use "&memo." for the string to resolve properly.

 

 

Note that I find a data set that has to be read this way if only one variable uses it to be very problematic

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 630 views
  • 0 likes
  • 3 in conversation