DATA Step, Macro, Functions and more

Meaning of set @ Memo = 'Aug 16'

Reply
Occasional Contributor
Posts: 6

Meaning of set @ Memo = 'Aug 16'

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());

Community Manager
Posts: 3,357

Re: Meaning of set @ Memo = 'Aug 16'

[ Edited ]
Posted in reply to astha8882000

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

Super User
Posts: 13,066

Re: Meaning of set @ Memo = 'Aug 16'

Posted in reply to astha8882000

@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

Ask a Question
Discussion stats
  • 2 replies
  • 89 views
  • 0 likes
  • 3 in conversation