SAS Tutorial | Using SAS Macro Variable Lists to Create Dynamic Data-Driven Programs

Sdílet
Vložit
  • čas přidán 6. 07. 2024
  • The SAS® macro facility is an amazing tool for creating dynamic, flexible, reusable programs that can automatically adapt to change. In this presentation, you’ll learn how to create and use macro variable lists, a simple but powerful mechanism for creating data-driven programming logic. Don’t hardcode data values into your programs. Eliminate data dependencies forever and let the macro facility write your SAS code for you!
    Content Outline
    00:00:00 - Introduction
    00:03:10 - Macro Language Review
    00:14:51 - Exercise 1 Using Data Step
    00:21:07 - Exercise 2 Using PROC SQL
    00:24:53 - Creating Macro Variable Lists
    00:28:16 - With PROC SQL - Horizontal list
    00:32:26 - Exercise 3
    00:35:18 - With PROC SQL - Vertical List
    00:37:21 - Exercise 4
    00:39:39 - With Data Step - Horizontal List
    00:46:25 - Exercise 5
    00:50:04 - With Data Step - Vertical List
    00:53:07 - Exercise 6
    00:56:00 - Using Macro Variable Lists
    00:56:29 - Using Horizontal Macro Variable Lists
    00:59:55 - Exercise 7
    01:05:59 - Using Vertical Macro Variable Lists
    01:09:22 - Exercise 8
    01:13:46 - Conclusion
    Session ID: N/A
    Presenter: Joshua Horstman, Nested Loop
    Topic: Programming
    Industry: Non-Industry Specific
    Audience: All
    Level: All
    Tutorial exercises and solutions -- github.com/sascommunities/sas...
    Learn more about SAS Software
    Free SAS Online Training - www.sas.com/en_us/training/of...
    Contact SAS® - www.sas.com/en_us/contact.geo...
    SUBSCRIBE TO THE SAS USERS CZcams CHANNEL #SASUsers #LearnSAS #SASGF
    czcams.com/users/SASUsers?sub_...
    ABOUT SAS
    SAS is a trusted analytics powerhouse for organizations seeking immediate value from their data. A deep bench of analytics solutions and broad industry knowledge keep our customers coming back and feeling confident. With SAS®, you can discover insights from your data and make sense of it all. Identify what’s working and fix what isn’t. Make more intelligent decisions. And drive relevant change.
    CONNECT WITH SAS
    SAS ► www.sas.com/contact
    SAS Customer Support ► support.sas.com
    SAS Communities ► communities.sas.com
    SAS Analytics Explorers ► explorers.sas.com
    Facebook ► / sassoftware
    Twitter ► / sassoftware
    LinkedIn ► / sas
    Blogs ► blogs.sas.com
    RSS ►www.sas.com/rss
  • Věda a technologie

Komentáře • 37

  • @kentlewan
    @kentlewan Před 4 lety +3

    Hey Josh, I watched the rest of this video, and learned something I immediately incorporated into my SAS report (a "vertical list".) Great presentation - and thanks!

  • @kirkpaullafler2230
    @kirkpaullafler2230 Před 4 lety +1

    Great tutorial, Josh!

  • @sunilgupta2156
    @sunilgupta2156 Před 4 lety +1

    Great tutorial Joshua!

  • @ashleymccook-veal1202
    @ashleymccook-veal1202 Před 3 lety +1

    Great presentation, I've learned so much in a brief period of time. I'm relatively a beginner when it comes to SAS macro and I feel like a lot of the dots are connecting. Also, you're right about the Carpenter book. I've only read section one but I'm definitely ready to finish the book after watching this.

    • @SASUsers
      @SASUsers  Před 3 lety

      Thanks for your great feedback, Ashley!
      Check out our #SAS Macro Language Focus Area for even more resources 2.sas.com/6058GfL1q Be sure to explore all of the tabs there so you don't miss anything!
      Some of our favorites:
      Documentation > SAS 9.4 Macro Language Reference > Getting Started with the Macro Facility 2.sas.com/6059GfL1S
      Communities: SAS Programming: DATA Step, Macro, Functions and more 2.sas.com/6050GfL1s
      Tip Sheet: SAS Macro Language Processing (PDF): 2.sas.com/6051GfL1t
      Wishing you much ongoing Macro & #SASsuccess!

  • @jessicasonbert6967
    @jessicasonbert6967 Před rokem

    Thanks so much for posting - very helpful!

    • @SASUsers
      @SASUsers  Před rokem

      Absolutely! Glad you enjoyed this piece!

  • @azulmii
    @azulmii Před 3 lety +2

    Great and usefull. Thanks!

    • @SASUsers
      @SASUsers  Před 3 lety

      Thanks for the positive feedback!

  • @nethajis5494
    @nethajis5494 Před 4 lety +1

    All the contents where really helpful thanks a lot.

  • @dominicmutiso1502
    @dominicmutiso1502 Před rokem

    I enjoyed this. proc sql is simply amazing

    • @SASUsers
      @SASUsers  Před rokem

      Awesome, glad you liked it!

  • @adityavarma1792
    @adityavarma1792 Před 4 lety

    Nice presentation 👍

    • @SASUsers
      @SASUsers  Před 4 lety

      We're glad you enjoyed it!

  • @rimalmahesh
    @rimalmahesh Před 4 lety

    Great resource

    • @SASUsers
      @SASUsers  Před 4 lety

      Thanks for sharing - we're glad you enjoyed the content!

  • @tamarabarker
    @tamarabarker Před 4 lety +1

    Great tutorial! A suggestion for this channel's moderators - Please include a link to the workshop files in the content description for this and any similar recording referencing provided files. I don't see it anywhere in the content description, so it's unclear where to get the files that Joshua has made available for viewers.

    • @SASUsers
      @SASUsers  Před 4 lety +1

      Thanks for your feedback, Tamara - we appreciate it, and we are checking into getting the files for you!

    • @SASUsers
      @SASUsers  Před 4 lety

      Okay Tamara -- we added the files to our SAS Global Forum GitHub, and put a link in the description. Thanks for the feedback!

  • @riteshchaudhary9776
    @riteshchaudhary9776 Před 3 lety +1

    hey, I have a doubt in exercise 1. If i want the price of every individual model of acura to be stored in macro variable and then display it in new column. How is that possible. Do i have to declare seperate macros for evey model under acura.???

    • @SASUsers
      @SASUsers  Před 3 lety

      Thank you for your inquiry! We are checking on this for you!

    • @SASUsers
      @SASUsers  Před 3 lety +1

      Ritesh, Exercise 1 only shows how to take one value for one Model for Acura and put it into one macro variable. If you are interested in creating a separate macro variable that holds the value of the price (either MSRP or Invoice from SASHELP.CARS) for very model for Acura, that would involve different coding technique. In terms of the video, it would be most similar to Exercise #4 "Creating a Vertical Macro Variable List Using PROC SQL" and with the DATA Step, similar to Exercise #6 "Creating a Vertical Macro Variable List Using the DATA Step".


      Here is some code you can run to show you how this could be done.

      /* Similar to Exercise 4 */
      proc sql noprint;
      select msrp into :AcuraMSRP1-
      from sashelp.cars
      where make="Acura"
      order by msrp ;
      %let nummodels=&sqlobs;
      quit;

      /* List the values of the vertical macro variable list created by SQL*/
      %put NOTE: &=AcuraMSRP1 &=AcuraMSRP2 &=AcuraMSRP3 &=AcuraMSRP4 &=AcuraMSRP5 &=AcuraMSRP6 &=AcuraMSRP7 &=nummodels;

      /* Similar to Exercise 6 */
      proc sort data=sashelp.cars out=sortedAcura;
      by msrp;
      where make="Acura";
      run;


      data _null_;
      set sortedAcura end=eof;
      call symputx(cats('A_MSRP',_n_),MSRP);
      if eof then call symputx('Num_Models',_n_);
      run;

      /* List the values of the vertical macro variable list created by DATA Step*/

      %put NOTE: &=A_MSRP1 &=A_MSRP2 &=A_MSRP3 &=A_MSRP4 &=A_MSRP5 &=A_MSRP6 &=A_MSRP7 &=Num_Models;

  • @kentlewan
    @kentlewan Před 4 lety +1

    Why just use 1 ampersand when you can use 3? :-)

  • @rohitwalopkar6953
    @rohitwalopkar6953 Před 2 lety

    how to save a filepath by macro variable??
    is it like %let outpath(or any other name)="location" coz this code is not working, when I am using code ods excel file = "&otpath/xyz.xlsx" ; (and other codes after it) the excel file is not getting saved in location and I cannot export it.
    Currently doing sas coursera course and Im stuck at this problem please reply...

    • @SASUsers
      @SASUsers  Před 2 lety

      Thank you for contacting SAS. Coursera students are encouraged to take advantage of the Discussion Forums offered as part of the course. You can find the Discussion Forums for your course by logging in to Coursera, going to your class, and then looking on the left for the Discussion Forums link. Note that these forums are monitored by SAS Curriculum Consultants, and they can provide information or direct you in another way as needed.

  • @dominicmutiso1502
    @dominicmutiso1502 Před rokem

    Is this content thorough with everything offered in SAS Macro Language 1: Essentials or do I have to follow the SAS Macro Language 1: Essentials in SAS/Coursera platform?

    • @SASUsers
      @SASUsers  Před rokem

      Checking on this for you!

    • @SASUsers
      @SASUsers  Před rokem

      This video content covers a small portion of the material in the full SAS Macro Language 1: Essentials SAS course/SAS Macro Language Coursera course.

    • @dominicmutiso1502
      @dominicmutiso1502 Před rokem

      @@SASUsers thank you

  • @riteshchaudhary9776
    @riteshchaudhary9776 Před 3 lety

    Hi SIr,
    I have doubt in extracting the macro variables created. I am using the following code to populate new column using the vertical macro list created for class. but in the logs i can see each name is being taken but in the output column only the last name is displayed in every record. Kindly help.
    Also tell the use of %macro name you are using after we end the macros.Thanks
    %macro rts;
    proc sql ;
    select distinct name into :name1-
    from sashelp.class;
    %let observations= &sqlobs;
    quit;
    %do i=1 %to &observations;
    data class_names;
    set sashelp.class;
    newname="&&name&i";
    %put &name1;
    run;
    %end;
    %mend rts;
    %rts;

    • @SASUsers
      @SASUsers  Před 3 lety

      Ritesh, thank you for your inquiry! We are researching this and will get back to you!

    • @SASUsers
      @SASUsers  Před 3 lety

      Unfortunately, we cannot provide code or screen shots or do detailed debugging in this CZcams feedback area. There is a very similar program to the one you are constructing at time stamp 1:11:55 in the video, where the presenter is using a macro %DO loop to create a unique output dataset for each value of the &ORIGIN macro variable. Note that in his program, he uses the indirect reference data cars_&&origin&i to create the datasets 2.sas.com/6056yrRre_ASIA, 2.sas.com/6056yrRre_EUROPE and 2.sas.com/6056yrRre_USA. Your best resource for debugging your program is to either open a track with SAS Tech Support or post in the Community Forum for SAS Programming questions, here: 2.sas.com/6057yrRr5 . To open a track with Tech Support, fill out the form at this link: 2.sas.com/6058yrRrg .

  • @priyap5827
    @priyap5827 Před 4 lety

    can you please zoom the code from next time, please?

  • @iam007richie
    @iam007richie Před 3 lety +1

    Not to be an ass but SAS reduce your licensing fees man. My firm is forcing everyone to learn "R" and "Python" and slowly reducing the dependence on SAS.
    Either lower your fees or do something that "R" and "Python" can't do

    • @SASUsers
      @SASUsers  Před 3 lety

      We would love to talk with you more about your current license set up to make sure you are getting the most out of SAS. Please email SAS_Cares@sas.com and include your contact information including your company name and country, so we can follow up!