Macro variables, creation methods and differences in SAS

Source: Internet
Author: User

/* Way One */

%let x=5; %let y=test; %put &x &y;

/* Mode two */

Data _null_; Call Symput (' x ', 5);

Call Symput (' y ', ' test ');

Run %put &x &y;

/* Mode three */* if there are multiple records, only the value of the first bar */

Proc SQL Noprint;

Select min (weight), max (weight) Into:minw,:maxw

From Sashelp.class;

Quit %put &MINW &maxw;

/* Create more than one macro variable and assign a value that is not created if the range of records is exceeded */

Proc SQL Noprint;

Select name, Age INTO:NAME1-: Name99999999,:age1-: age99999999 from Sashelp.class;

Quit

%put &sqlobs;

%put &name1 &age1;

%put &name2 &age2;

%put &&name&sqlobs &&age&sqlobs;

%put &name100 &age100;/* These two macro variables are not created, the execution will be reported warning*/*/* stitching field values, assigned to a macro variable */proc SQL Noprint inobs=5; Select name Into:names separated by ', ' from Sashelp.class; Quit

%put names=&names;

The difference between the three methods is: 1.  %let xxx=yyy; /*%let statements define macro variables almost anywhere in the program */
2. Call symput (' xxx ', ' yyy '); /* can only be defined in date step, the macro variable defined by call Symput in the macro function may be used out of the function;
3. Select XXX into:yyy. /* can only be defined in proc SQL */
%let and Select into these 2 methods generated in the macro function is a local macro variable, if you want to use the macro function, you need to declare the variable type in advance with%global.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.