DATA Step, Macro, Functions and more

Macros basic

Reply
Occasional Contributor
Posts: 7

Macros basic

[ Edited ]

As a beginner I want to know how to learn macros ,please share any books, websites which can help in learning macros easily

SAS Moderator
Posts: 48

Re: Macros basic [how to improve your question]

Hello @Sama1,


Your question requires more details before experts can help. Can you revise your question to include more information? 

 

Review this checklist:

  • Specify a meaningful subject line for your topic.  Avoid generic subjects like "need help," "SAS query," or "urgent."
  • When appropriate, provide sample data in text or DATA step format.  See this article for one method you can use.
  • If you're encountering an error in SAS, include the SAS log or a screenshot of the error condition. Use the Photos button to include the image in your message.
    use_buttons.png
  • It also helps to include an example (table or picture) of the result that you're trying to achieve.

To edit your original message, select the "blue gear" icon at the top of the message and select Edit Message.  From there you can adjust the title and add more details to the body of the message.  Or, simply reply to this message with any additional information you can supply.

 

edit_post.png

SAS experts are eager to help -- help them by providing as much detail as you can.

 

This prewritten response was triggered for you by fellow SAS Support Communities member @KurtBremser

.
Respected Advisor
Posts: 2,661

Re: Macros basic

[ Edited ]

Sama1 wrote:
Create a macro that includes a dataset that contains observations with a date variable containing dates for March, 2017. Assign the month name to one macro variable and year number to another macro variable. Output a CSV file where the resulting file name includes value of the two macro variables within the name. Eg: “Filename_March_2017.csv”

Thanks

Yes, of course SAS can create these macro variables. It's probably not a good idea to use “Filename_March_2017.csv”, because this won't sort properly, it will sort alphabetically in your operating system. A better result would be to “Filename_2017-03.csv”, which will sort properly in your operating system.

 

Something like this, assuming ALL date values in your data set are in the same month (UNTESTED CODE)

 

data _null_;
    set have(obs=1);
    call symputx('year_month',put(date,yymmd7.));
run;
--
Paige Miller
Occasional Contributor
Posts: 7

Re: Macros basic

Thank you very much
Ask a Question
Discussion stats
  • 3 replies
  • 207 views
  • 0 likes
  • 3 in conversation