相关日志
-
-
分享
【转自online tutor】SAS宏小结
-
huahuaaiqingtia 2015-6-17 09:19
-
1. systematic macro SYSDATE the date of the SAS invocation (DATE7.) SYSDATE9 the date of the SAS invocation (DATE9.) SYSDAY the day of the week of the SAS invocation SYSTIME the time of the SAS invocation SYSENV FORE (interactive execution) or BACK (noninteractive or batch execution) SYSSCP an abbreviation for the operating system that is being used, such as OpenVMS, WIN, HP 300 SYSVER the release of SAS that is being used SYSJOBID an identifier for the current SAS session or for the current batch job (the user ID or job name for mainframe systems, the process ID (PID) for other systems) Some automatic macro variables have values that automatically change based on submitted SAS statements. SYSLAST the name of the most recently created SAS data set, in the form LIBREF.NAME. This value is always stored in all capital letters. If no data set has been created, the value is _NULL_ SYSPARM text that is specified when SAS is invoked SYSERR contains a return code status that is set by the DATA step and some SAS procedures to indicate if the step or procedure executed successfully 2.user-defined macro The %LET Statement Displaying Macro Variable Values in the SAS Log The SYMBOLGEN Option The %PUT Statement _ALL_ Lists the values of all macro variables _AUTOMATIC_ Lists the values of all automatic macro variables _USER_ Lists the values of all user-defined macro variables %STR function hides the normal meaning of a semicolon and other special tokens and mnemonic equivalents of comparison or logical operators so that they appear as constant text. %NRSTR function performs the same quoting function as %STR, except it also masks macro triggers ( and % %BQUOTE function is used to mask (or quote) special characters and mnemonic operators Macro Functions The %UPCASE Function The %QUPCASE Function The %SUBSTR Function: enables you to extract part of a character string from the value of a macro variable The %QSUBSTR Function The %INDEX Function The %SCAN Function:enables you to extract words from the value of a macro variable The %QSCAN Function The %SYSFUNC Function Creating a Macro Variable During DATA Step Execution CALL SYMPUT(macro-variable,text); CALL SYMPUT(‘macro-variable’, ‘text’); CALL SYMPUT(‘macro-variable’,DATA-step-variable); CALL SYMPUTX(macro-variable,expression); CALL SYMPUT(‘macro-variable’,expression); PUT(source,format.) CALL SYMPUT(expression1,expression2); Creating Macro Variables During PROC SQL Step Execution PROC SQL NOPRINT; SELECT column1,column2,... INTO :macro-variable-1,:macro-variable-2,... FROM table-1 | view-1 WHERE expression other clauses; QUIT; PROC SQL NOPRINT; SELECT column1 INTO :macro-variable-1 SEPARATED BY ‘delimiter1’ FROM table-1 | view-1 WHERE expression other clauses; QUIT; Working with PROC SQL Views proc sql; create view subcnum as select student_name, student_company, paid from sasuser.all where course_number=input(symget(’crsnum’),2.); quit; %let crsnum=4; proc print data=subcnum noobs; title "Status of Students in Course Number crsnum"; run; Using Macro Variables in SCL Programs Referencing Macro Variables Indirectly Obtaining Macro Variable Values During DATA Step Execution SYMGET(macro-variable) CALL SYMPUTN(‘macro-variable’, value); SCL-variable = SYMGETN(‘macro-variable’); 3.macro??? Defining a Macro %MACRO macro-name; text %MEND macro-name; OPTIONS MCOMPILENOTE= NONE | NOAUTOCALL | ALL; Monitoring Execution with System Options OPTIONS MPRINT | NOMPRINT; -------- specified, the text that is sent to the SAS compiler as a result of macro execution is printed in the SAS log OPTIONS MLOGIC | NOMLOGIC; --------- prints messages that indicate macro actions that were taken during macro execution. 4.????macro??? (1)Positional Parameters %MACRO macro-name(parameter-1,...,parameter-n); text %MEND macro-name; (2)Keyword Parameters %MACRO macro-name(keyword-1=value-1,...,keyword-n=value-n); text %MEND macro-name; (3)Mixed Parameter Lists %MACRO macro-name(parameter-1,...,parameter-n, keyword-1=value-1,...,keyword-n=value-n); text %MEND; PARMBUFF option in a macro definition to create a macro that can accept a varying number of parameters at each invocation. 5. Global and local You can create a global macro variable with a %LET statement (used outside a macro definition) a DATA step that contains a SYMPUT routine a DATA step that contains a SYMPUTX routine (beginning in SAS 9) a SELECT statement that contains an INTO clause in PROC SQL The %GLOBAL statement -creates one or more macro variables in the global symbol table and assigns null values to them -can be used either inside or outside a macro definition - has no effect on variables that are already in the global symbol table. %GLOBAL macro-variable-1 ...macro-variable-n; local macro variables with parameters in a macro definition a %LET statement within a macro definition a DATA step that contains a SYMPUT routine within a macro definition a DATA step that contains a SYMPUTX routine within a macro definition (beginning in SAS 9) a SELECT statement that contains an INTO clause in PROC SQL within a macro definition a %LOCAL statement. The %LOCAL statement - can appear only inside a macro definition - creates one or more macro variables in the local symbol table and assigns null values to them - has no effect on variables that are already in the local symbol table Remember, the SYMPUT routine and the SYMPUTX routine can create local variables only if the local table already exists. it is possible to have a local macro variable and a global macro variable that have the same name and different values. OPTIONS MPRINTNEST | NOMPRINTNEST; ----------- allows the macro nesting information to be written to the SAS log in the MPRINT output. This has no effect on the MPRINT output that is sent to an external file. OPTIONS MLOGICNEST | NOMLOGICNEST; -----------allows the macro nesting information to be displayed in the MLOGIC output in the SAS log. 6. Structured statements (1)Conditionally %IF expression %THEN text; %ELSE text; %IF expression %THEN %DO; text and/or macro language statements %END; %ELSE %DO; text and/or macro language statements %END; (2)Iteratively %DO index-variable=start %TO stop %BY increment; text %END; (3)Using Arithmetic and Logical Expressions %EVAL(arithemetic or logical expression); evaluates integer arithmetic or logical expressions. Logical expressions and arithmetic expressions are sequences of operators and operands forming sets of instructions that are evaluated to produce a result. %SYSEVALF(expression, conversion-type); evaluates arithmetic and logical expressions using floating-point arithmetic.
-
32 次阅读|0 个评论
-
-
分享
Micro & Macro Data
-
aliehs 2013-8-5 22:43
-
What is macro data? The terms micro and macro data are often used to denote data used in social science research. The distinction between them is, however, not always obvious. Micro data Micro data can generally be described as individual level data. These data have often been collected from each individual through a survey or interview. In such a dataset, each row typically represents an individual person and each column an attribute such as age, gender or job-type. Some well-known surveys that collect this type of data include the European Social Survey (ESS), the General Social Survey (GSS), the World Values Survey (WVS) etc. 'Micro data' would also denote data on individuals collected from governmental administrative systems and registers. While the main distinction is most often drawn between micro and macro data, the term 'meso data' is also sometimes used. Meso data generally refers to data on collective and cooperative actors such as commercial companies, organizations or political parties. Macro data 'Macro data' is generally a term used to describe mainly two subtypes of data; aggregated data system-level data Aggregated macro data provide information constructed by combining information on the lower level units, which the higher level unit is composed of (Diez-Roux 2002). Examples of aggregate data include summaries of the properties of individuals, unemployment statistics, demographics, GDP etc. Most often, aggregated macro data imply that the variables are summaries of the properties of lower level units and not measures of inherent higher level properties. System level macro data yield information about properties of the state or the political system and cannot be disaggregated to lower level units. This type of data form political indicators, such as institutional variables and regime indices, and is not based on summaries of the properties of lower-level units, but measures characteristics of the higher-level units themselves. The MacroDataGuide provides links and qualitative information on a wide range of both aggragated and system-level macro data sources. References Diez-Roux, Ana V. 2002. “A glossary for multilevel analysis”. Journal of Epidemiology and Community Health 56 (August): 588-594. BTW a good glossary of social science data terms: http://3stages.org/glossary/glossary.html#micro
-
个人分类: Data Analysis|104 次阅读|0 个评论
GMT+8, 2025-12-25 01:58