SAS macro (2), run in Create macro with macro, proc SQL create macro, SCL in macro processing (n/a)

Source: Internet
Author: User

1: Macro definition in program run

Call Routines -enable you-transfer information between an executing DATA step and the Macro Proces Sor.

You can use the symput routine to create a macro variable, and to assign to, variable any value, is Availa ble in the DATA step.

Symput routine to create a macro variable in a DATA step, the macro variable are not actually cre Ated and assigned a value until the DATA step is executed.

Options Symbolgen pagesize= -; %Let Crsnum=3; data revenue; SetSasuser. All End=final;whereCourse_number=&Crsnum; Total+1; ifPaid='Y'  ThenPaidup+1; ifFinal ThenDo ; ifPaidup<Total ThenDo ; Call Symput ('Foot','Some Fees is unpaid'); the/*symput function can achieve the effect of assigning values to macros at run time *          //*%let foot=some Fees is unpaid; * //////////////////////////    End; ElseDo ; Call Symput ('Foot','All Students has Paid'); /*%let foot=all Students have paid;*/     End; End; Run;

The argument inside the Symput function is the case of an expression

The function referenced inside does not need to use the notation of this macro function

Trim to left end to right end

Call Symput ('numpaid', trim ( left

Create a macro based on the variable name

data _null_; Set Sasuser.courses;call symput (Course_code, Trim (course_title)); /* Two variables in each observation to the macro value and the macro variable */run; %put _user_;

Scan rules for multiple macro triggers

The macro processor treats two & as one, so the first scan &&&lv2 is processed into & (&LV2)->&lv1, and the second scan draws res

The &&LV2 first scan was processed into &LV2, and the result is still LV1

/* Want to use LV2 to get res*/
Data _null_; % = Res; % = Lv1; % & Lv2;/* A red trigger does not need to be explained, the result is lv1*/ % && Lv2;/* This looks plausible, but the result is lv1*/ % &&& lv2;/* The result of this is res*/run;

2: Macro is worth getting in the program running

It is not possible to make a macro in a program with &, which is the statement executed before compiling.

data teachers; Set  teacher=symget ('teach'| | left(course_number)); run;

3: Create macros with proc SQL

/ * Create multiple macro variables in the case of a number of rows */
ProcSQL Noprint; Select Count(*) into: NumRows fromSasuser.schedulewhere Year(begin_date)=2002;%Let NumRows=&NumRows; / * Eliminate the blanks * /%Put there is&NumRows Coursesinch 2002; SelectCourse_code, location, begin_date format=Mmddyy10. into: CRSID1-: Crsid&numrows,:p Lace1-:p Lace&numrows,:d ate1-:d ate&NumRows fromSasuser.schedulewhere Year(begin_date)=2002 Order bybegin_date;%put _user_;quit;

Create One macro variable that would Hold all values of a certain data set variable.

proc SQL noprint;     Select distinct  into  by ' '         from Sasuser.schedule;quit;

Global symbol table (symbol table, macro and macro values)
Sites Boston Dallas Seattle

Automatic data type conversions are not performed in Proc SQL. Manual conversion for the type of data you want to use

SAS macro (2), run in Create macro with macro, proc SQL create macro, SCL in macro processing (n/a)

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.