tag 标签: SAS经管大学堂:名校名师名课


版块 作者 回复/查看 最后发表
notepad++ 实现SAS语法高亮 SAS专版 cauchyok 2013-9-2 7 8302 Peterlie 2019-5-21 13:02:06
悬赏 求SAS 9.3 64位 最新的SID 送论坛币 - [!reward_solved!] attachment SAS专版 ablwxxy 2019-4-28 5 557 cnzxcxt1 2019-5-7 08:01:40
合并表 更新数据 SAS专版 jjltcfa 2013-7-14 12 6659 yisha9199 2019-2-15 10:24:41
sas9.3 64位 下载 8.81G 百度网盘 数据分析与数据科学 d2071d 2013-3-18 30 23521 baoji777 2018-9-10 15:07:51
从多方面全面解析SAS/EIS SAS专版 sunorzeng 2012-7-31 8 10084 yuan_wang 2018-6-17 03:47:27
每次打开sas软件时都会提示OLE,什么问题呢? attach_img SAS专版 mzyoung 2013-6-21 11 10258 高新软件 2017-11-30 22:05:46
请教大家 proc univariate 中var的用法 SAS专版 jjltcfa 2013-7-24 7 13273 Peiming_Li 2017-3-3 08:52:05
SAS9.3 安装过程中SAS/SECURE java component安装失败,跳过该步之后无法继续安装。 attach_img 爱问频道 杜松旧友 2013-6-6 2 8491 shadowaver 2016-12-4 18:11:59
SAS学习笔记之创建Data文件 SAS专版 zhou.wen 2012-8-15 18 14086 经济学balabala 2016-9-21 23:48:15
SAS学习笔记之画图初步 attach_img SAS专版 zhou.wen 2012-8-22 14 17011 magiclander 2016-5-1 22:02:43
[资料]应用回归分析 张小蒂 attachment 数据分析与数据科学 KSEI0725622 2012-12-7 11 8516 liyanruwang 2015-12-4 17:32:58
SAS Data Integration Studio SAS专版 你看到了吗 2013-2-25 1 987 leiding7897 2013-10-19 03:25:53
sas学习 SAS专版 a野丫头 2013-7-23 6 5435 freecat777 2013-8-1 14:24:46
悬赏 求助,数据处理问题 - [!reward_solved!] SAS专版 jjltcfa 2013-7-12 9 1341 jjltcfa 2013-7-12 17:27:53
Using the Name Pipes to Communicate among Different SAS Sessions attach_img SAS专版 zhou.wen 2013-4-19 5 1500 zll_zh 2013-5-24 13:04:14
求助:SAS中ARIMA的用法 SAS专版 minghaorenda 2013-4-6 2 10432 minghaorenda 2013-4-6 11:47:57


BenjaminSAS 2017-8-16 10:28
截止目前,所有Base考试知识点已经掌握。准备迎战啦~~ 高频率机经复习
个人分类: SAS Base|4 次阅读|0 个评论
BenjaminSAS 2017-8-4 03:59
今天主要任务: 完全70题中的最后20题
个人分类: SAS Base|0 个评论
分享 SAS Base 备考 Day 11
BenjaminSAS 2017-7-24 04:49
Enhancing HTML Tabular Reports
个人分类: SAS Base|1 次阅读|0 个评论
分享 SAS BASE 备考 Day 10
BenjaminSAS 2017-7-23 05:17
今天主要任务 完成: Creating Tabular Reports
个人分类: SAS Base|0 个评论
分享 SAS Base 备考 Day 9
BenjaminSAS 2017-7-22 04:48
今日主要任务: Producing HTML Output
个人分类: SAS Base|0 个评论
分享 SAS Base 备考 Day 8
BenjaminSAS 2017-7-21 00:29
今日主要任务: Producing Descriptive Statistics
个人分类: SAS Base|0 个评论
分享 SAS Base 备考 Day 7
BenjaminSAS 2017-7-19 21:59
Producing Reports Creating and Applying User-Defined Formats Creating Enhanced List and Summary Reports
个人分类: SAS Base|0 个评论
分享 SAS BASE 备考 Day 6
BenjaminSAS 2017-7-18 22:40
今天的主要任务: Understanding DATA Step Processing Producing Reports Creating and Applying User-Defined Formats
个人分类: SAS Base|0 个评论
分享 SAS BASE 备考 Day 5
BenjaminSAS 2017-7-18 05:08
今天主要任务: 完成以下内容 Creating SAS Data Sets from Raw Data Understanding DATA Step Processing
个人分类: SAS Base|0 个评论
分享 SAS Base 备考 Day 4
BenjaminSAS 2017-7-16 03:23
今天的主要任务: Introduction to SAS Programming Basic Concepts Using the Programming Workspace Referencing Files and Setting Options
个人分类: SAS Base|0 个评论
分享 SAS Base 备考 Day 3
BenjaminSAS 2017-7-15 08:01
今天的主要任务: Introduction to SAS Programming Using the Programming Workspace
个人分类: SAS Base|0 个评论
分享 SAS Base 备考 Day 2
BenjaminSAS 2017-7-14 11:15
今天主要任务: 完成 SAS Online Tutor Introduction to SAS Programming 完成时间: 7/13/2017 11:15 PM Basic Concepts
个人分类: SAS Base|0 个评论
分享 SAS Base 备考 Day 1
BenjaminSAS 2017-7-12 23:30
Day 1 今天主要任务: 1. 了解SAS考试范围以及考试要求 SAS 官网:https://www.sas.com/en_us/certification/credentials/foundation-tools/base-programmer.html 2. 搜集备考资料 3. 制定备考计划 4. 注册考试 备考资料: 1. 参考 mikeleung110 的经验贴:https://bbs.pinggu.org/thread-4172814-1-1.html 2. 下载mikeleung110中的资料 3. SAS online tutor: https://jpsmonline.umd.edu/SASOnlineTutor/sot12/en/60476/paths.htm 备考计划: 7.13.2017-7.16.2017 完成Introduction to SAS Programming 7.17.2017-7.23.2017 完成 Producing Reports 7.24.2017-7.30.2017 完成 Producing Graphical Reports 7.31.2017-8.6.2017 完成 Creating and Modifying SAS Data Sets 8.07.2017-8.13.2017 完成 Reading Various Types of Raw Data 8.13.2017-8.18.2017 题库 8.19.2017 考试 备注:以上备考计划安排根据具体情况调整,计划考试时间8.19.2017. ------------------------------------------------------------------------------ 实际进度: 提前于 7.31 完成了SAS online tutor
个人分类: SAS Base|0 个评论
分享 【转自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.
3 次阅读|0 个评论
分享 【转自online tutor】SAS 数据管理
huahuaaiqingtia 2015-6-16 08:05
1. create sample 2. create index 3. combine data 1. create sample (1) systematic sample of known # of obs data sasuser.subset; do pickit=1 to 142 by 15; set sasuser.revenue point=pickit; output; end; stop; run; (2) systematic sample of unknown # of obs data sasuser.subset; do pickit=1 to totobs by 10; set sasuser.revenue point=pickit nobs=totobs; output; end; stop; run; (3) random sample with replacement data work.rsubset(drop=1 sampsize); sampsize=10; do i=1 to sampsize; pickit=ceil(ranuni(0)*totobs); set sasuser.revenue point=pickit nobs=totobs; output; end; stop; run; proc print data=work.rsubset label; title 'A Random Sample with Replacement'; run; (4)random sample without replacement data work.rsubset(drop=obsleft sampsize); sampsize=10; obsleft=totobs; do while(sampsize0); pickit+1; if ranuni(0)sampsize/obsleft then do; set sasuser.revenue point=pickit nobs=totobs; output; sampsize=sampsize-1; end; obsleft=obsleft-1; end; stop; run; proc print data=work.rsubset label; title 'A Random Sample without Replacement'; run; 2. create index in data step manage index with proc datasets manage index with proc sql 3. combine data (1) filename statement filename qtr1('add1' 'add2' 'add3'); data work.firstqtr; infile qtr1; input Flight $ Origin $ Dest $ Date: date9. Revcargo: comma15.2; run; (2) infile statement data quarter (drop=monthnum midmon lastmon); monthnum=month(today()); midmon=month(intnx('month', today(), -1)); lastmon=month(intnx('month',today,-2)); do i=mnthnum, midmon, lastmon; nextfile=""!!compress(put(i,2.)!!".dat",' '); do until(lastobs); infile temp filevar=nextfile end=lastobs; input Flight $ Origin $ Dest $ Date: date9. Revcargo: comma15.2; output; end; stop; run; (3)proc append proc append base=work.acities data=work.airports force; run; (4) if-then/else statement data mylib.employees_new; set mylib.employees; if IDnum=1001 then Birthdate='01JAN1963'd; else if IDnum=1002 then Birthdate='08AUG1946'd; else if IDnum=1003 then Birthdate='23MAR1950'd; else if IDnum=1004 then Birthdate='17JUN11973'd; run; (5) array statement data mylib.employees_new; array birthdates{1001:1004} _temporary_ ( '01JAN1963'd '08AUG1946'd '23MAR1950'd '17JUN11973'd ); set mylib.employees; Bithdate=birthdates(IDnum); run; (6)format procedure proc format; value $birthdate '1001'= '01JAN1963'd '1002'='08AUG1946'd '1003'='23MAR1950'd '1004'='17JUN11973'd; run; data mylib.employees_new; set mylib.employees; Birthdate=input(put(IDnum,$birthdate.),date9.); run; (7) match-merge proc sort data=sasuser.expenses out=expenses; by flightid date; run; proc sort data=sasuser.revenue out=expenses; by flightid date; run; datarevexpns (drop=rev1st revbusiness revecon expenses); merge expenses(in=e) revenue(in=r); by flightid date; if e and r; Profit=sum(rev1st, revbusiness, revecon, -expenses); run; data sasuser.alldata; merge revexpns (in=r) acities (in=a rename=(code=dest) keep=city name code); by dest; if r and a; run; (8) sql proc sql; create table sqljoin as select revenue.flightid, revenue.date format=date9., revenue.origin, revenue.dest, sum(revenue.rev1st, revenue.revbusiness, revenue.revecon)-expenses.expenses as Profit, acities.city, acities.name from sasuser.expenses, sasuser.revenue, sasuser.acities where expenses.flightid=revenue.flightid and expenses.date=revenue.date and acities.code=revenue.dest order by revenue.dest, revenue.flightid, revenue.date; quit; (9) many-to-many match proc sql; create table flightemp as select flightschedule.*, firstname, lastname from sasuser.flightschedule, sasuser.flightattendants where flightschedule.empid=flightattendants.empid; quit; data fightemps3(drop=empnum jobcode) set sasuser.flightschedule; do i=1 to num; set sasuser.flightattendants(rename=(empid=empnum)) nob=num point=1; if empid=empnum then output; end; run; (10) summary data and detail data proc means data=sasuser.monthsum noprint; var revcargo; output out=sasuser.summary sum=Cargosum; run; data sasuser.percent1; if _n_=1 then set sasuser.summary(keep=cargosum); set sasuser.monthsum(keep=salemon revcargo); PctRev=revcargo/cargosum; run; data sasuser.percent2(drop=totalrev); if _n_=1 then do until(lastobs); set sasuser.monthsum(keep=revcargo) end=lastobs; totalrev+revcargo; end; set sasuser.monthsum (keep=salemon revcargo); PctRev=revcargo/totalrev; run; (11)index data work.profit work.errors; set sasuser.dnunder; set sasuser.sale200(keep=routeid flightid date rev1st revbusiness revecon revcargo) key=flightdate; if _iorc_=0 then do; Profit=sum(rev1st, revbusiness, revecon, revcargo, -expenses); output work.profit; end; else do; _error_=0; output work.errors; end; run; (12) multidimensional array data work.wndchill(drop=column row); array WC {4,2} _temporary_(-22, -16, -28, -22, -32, -26, -35, 29); set sasuser.flights; row=round(wspeed,5)/5; colunm=(round(temp,5)/5)+3; WindChill=wc{row, column}; run; (13) stored array values data work.lookup1; array Targets{1997:1999,12} _temporary_; if _n_=1 then do i=1 to 3; set sasuser.ctargets; array Mnth{*} Jan--Dec; do j=1 to dim(mnth); targets{year,j}=mnth{j}; end; end; set sasuser.monthsum(keep=salemin revargo monthno); year=input(substr(salemon,4),4.); Ctarget=targets{year,monthno}; format ctarget dollar15.2; run; (14) transpose and merge proc transpose data=sasuser.ctargets out=work.ctarget2 name=Month prefix=Ctarget; by year; run; proc sort data=work.ctarget2; by year month; run; data work.mnthsum2; set sasuser.monthsum(keep=SaleMon RevCargo); length Month $ 8; Year=input(substr(SaleMon,4),4.); Month=substr(SaleMon,1,1)||lowcase(substr(SaleMon,2,2)); run; proc sort data=work.mnthsum2; by year month; run; data work.merged; merge workmnthsum2 work.ctarget2; by year month; run;
1 次阅读|3 个评论
分享 bootstrap by SAS
intheangel 2014-5-14 23:01
come from http://www.ats.ucla.edu/stat/sas/faq/bootstrap.htm SAS FAQ: How can I bootstrap estimates in SAS? Bootstrapping allows for estimation of statistics through the repeated resampling of data. In this page, we will demonstrate several methods of bootstrapping a confidence interval about an R-squared statistic in SAS. We will be using the hsb2 dataset that can be found here. We will begin by running an OLS regression, predicting read with female, math, write, and ses, and saving the R-squared value in a dataset called t0. The R-squared value in this regression is 0.5189. ods output FitStatistics = t0; proc reg data = hsb2; model read = female math write ses; run; quit; The REG Procedure Model: MODEL1 Dependent Variable: read reading score Number of Observations Read 200 Number of Observations Used 200 Analysis of Variance Sum of Mean Source DF Squares Square F Value Pr F Model 4 10855 2713.73294 52.58 .0001 Error 195 10064 51.61276 Corrected Total 199 20919 Root MSE 7.18420 R-Square 0.5189 Dependent Mean 52.23000 Adj R-Sq 0.5090 Coeff Var 13.75493 Parameter Estimates Parameter Standard Variable Label DF Estimate Error t Value Pr |t| Intercept Intercept 1 6.83342 3.27937 2.08 0.0385 female 1 -2.45017 1.10152 -2.22 0.0273 math math score 1 0.45656 0.07211 6.33 .0001 write writing score 1 0.37936 0.07327 5.18 .0001 ses 1 1.30198 0.74007 1.76 0.0801 *store the estimated r-square; data _null_; set t0; if label2 = "R-Square" then call symput('r2bar', cvalue2); run; To bootstrap a confidence interval about this R-squared value, we will first need to resample. This step involves sampling with replacement from our original dataset to generate a new dataset the same size as our original dataset. For each of these samples, we will be running the same regression as above and saving the R-squared value. proc surveyselect allows us to do this resampling in one step. Before carrying out this step, let's outline the assumptions we are making about our data when we use this method. We are assuming that the observations in our dataset are independent. We are also assuming that the statistic we are estimating is asymptotically normally distributed. We indicate an output dataset, a seed, a sampling method, and the number of replicates. The sampling method indicated, urs, is unrestricted random sampling, or sampling with replacement. The samprate indicates how large each sample should be relative to the input dataset. A samprate of 1 means that the sampled datasets should be of the same size as the input dataset. So in this example, we will generate 500 datasets of 200, so our output dataset bootsample will have 100,000 observations. %let rep = 500; proc surveyselect data= hsb2 out=bootsample seed = 1347 method = urs samprate = 1 outhits rep = rep; run; ods listing close; The SURVEYSELECT Procedure Selection Method Unrestricted Random Sampling Input Data Set HSB2 Random Number Seed 1347 Sampling Rate 1 Sample Size 200 Expected Number of Hits 1 Sampling Weight 1 Number of Replicates 500 Total Sample Size 100000 Output Data Set BOOTSAMPLE With this dataset, we will now run our regression model, specifying by replicate so that the model will be run separately for each of the 500 sample datasets. After that, we use a data step to convert the R-squared values to numeric. ods output FitStatistics = t (where = (label2 = "R-Square")); proc reg data = bootsample; by replicate; model read = female math write ses; run; quit; * converting character type to numeric type; data t1; set t; r2 = cvalue2 + 0; run; Method 1: Normal Distribution Confidence Interval We will first create a confidence interval using the normal distribution theory. This assumes that the R-squared values follow a t distribution, so we can generate a 95% confidence interval by about the mean of the R-squared values based on quantiles from a t-distribution with 499 degrees of freedom. We find the critical t values for our confidence interval and multiply these by the standard deviation of the R-squared values that arose in our 500 replications. Our confidence interval using this method is symmetric about the R-squared value we saw in our original regression. We can see that the 95% confidence interval using this method is (0.432787, 0.605013). We have also calculated the bias in our original value of R-squared as the difference between that value and the mean of the 500 R-squareds in our bootstrap sample. * creating confidence interval, normal distribution theory method; * using the t-distribution; %let alphalev = .05; ods listing; proc sql; select r2bar as r2, mean(r2) - r2bar as bias, std(r2) as std_err, r2bar - tinv(1-alphalev/2, rep-1)*std(r2) as lb, r2bar + tinv(1-alphalev/2, rep-1)*std(r2) as hb from t1; quit; r2 bias std_err lb hb 0.5189 0.006616 0.043829 0.432787 0.605013 Method 2: Percentile Confidence Interval Another way to generate a bootstrap 95% confidence interval from the sample of 500 R-squared values is to look at the 2.5th and 97.5th percentiles in this distribution. This approach to the confidence interval has some advantages over the normal approximation used above. This interval is not symmetric about the original estimate of the R-squared and this method is unaffected by monotonic transformations on the estimated statistic. The first advantage is relevant because our original estimate is subject to bias. The second advantage is less relevant in this example than in an instance where the estimate might be subject to a transformation. The bootstrap estimates that form the bounds of the interval can be transformed in the same way to create the bootstrap interval of the transformed estimate. We can easily generate a percentile confidence interval in SAS using proc univariate after creating some macro variables for the percentiles of interest and using them in the output statement. We can see that the confidence interval from this method is (0.436, 0.6017). Since we have put the information of interest into a new dataset, pmethod, we have omitted the standard output from the proc univariate. %let alphalev = .05; %let a1 = %sysevalf(alphalev/2*100); %let a2 = %sysevalf((1 - alphalev/2)*100); * creating confidence interval, percentile method; proc univariate data = t1 alpha = .05; var r2; output out=pmethod mean = r2hat pctlpts=a1 a2 pctlpre = p pctlname = _lb _ub ; run; ... output omitted ... data t2; set pmethod; bias = r2hat - r2bar; r2 = r2bar; run; ods listing; proc print data = t2; var r2 bias p_lb p_ub; run; Obs r2 bias p_lb p_ub 1 0.5189 .0066164 0.436 0.6017 Method 3: Bias-Corrected Confidence Interval We can also correct for bias in calculating our confidence interval. We have calculated bias in the previous method as the difference between the R-squared we observed in our initial regression and the mean of the 500 R-squared values from the bootstrap samples. The R-squared estimate from the initial regression is assumed to be an unbiased estimate of the true R-squared. If we wish to correct for the bias in calculating our confidence interval, we can go through the steps below. These are described by Cameron and Trivedi in Microeconomics Using Stata. We first calculate the proportion of the bootstrap R-squareds that are less than our original value. We will adjust the percentiles used to define our confidence interval based on how this proportion differs from 0.5. We then find the probit of this proportion (z0) and the proportion associated with our alpha level (zalpha). Next, we calculate the two percentiles that will be used to find our confidence interval, p1 and p2, from these values. We then calculate our interval with proc univariate. From this method, our interval is (0.40575, 0.5936). %let alphalev = .05; %let alpha1 = %sysevalf(1 - alphalev/2); %put alpha1; proc sql; select sum(r2=r2bar)/count(r2) into :z0bar from t1; quit; 0.44 data _null_; z0 = probit(z0bar); zalpha = probit(alpha1); p1 = put(probnorm(2*z0 - zalpha)*100, 3.0); p2 = put(probnorm(2*z0 + zalpha)*100, 3.0); output; call symput('a1', p1); call symput('a2', p2); run; * creating confidence interval, bias-corrected method; proc univariate data = t1 alpha = .05; var r2; output out=pmethod mean = r2hat pctlpts=a1 a2 pctlpre = p pctlname = _lb _ub ; run; ... output omitted ... data t2; set pmethod; bias = r2hat - r2bar; r2 = r2bar; run; ods listing; proc print data = t2; var r2 bias p_lb p_ub; run; Obs r2 bias p_lb p_ub 1 0.5189 .0066164 0.40575 0.5936
个人分类: 网络文章(随笔)|6 次阅读|0 个评论
分享 处理SAS的日期数据
唐宝2011 2014-1-4 10:36
处理 SAS 的日期数据 日期数据的处理很棘手,有的月份有 31 天、有的 30 天、有的 28 天。 SAS 简化的日期数据,将所有的日期转化成一个以 1960 年 1 月 1 日为起点的数。比如: SAS 处理日期数据的三个工具为:读取数据的 informats ,使用数据的函数( functions ),打印数据的 formats Informats 读取日期数据需要用 formatted input 。比如,如何告诉 SAS 用 MMDDYY10. imforat 读取名为 BirthDate 的变量: INPUT BirthDate MMDDYY10.; 设定默认的百年 07/04/76 这样的数据可能是 1976 ,也可能是 2076 、 1776 。因此需要 YEARCUTOFF= 来指定一个一百年的第一年,默认的是 1920 年。下面的语句就是告诉 SAS 将一个两位年份的日期解释为 1960 年到 2049 年之间: OPTIONS YEARCUTOFF=1950; SAS 表达式中的日期 一旦被以 SAS 日期格式读取之后,可以将此数据想其他数值数据一样用在表达式中。比如像为图书馆的书设定 21 天的还书日期,只需要在结束日期上加上 21 : DueDate = CheckDate + 21; 通过在表达式中加入引号和字母 D ,可以将一个日期当做常数来使用,如下的代码创建了一个 EarthDay05 的变量,并且等于 April 22,2005 EarthDay05='22APR2005'D; 函数 SAS 日期函数使得操作大大简便,比如 today ()返回今天的日期。 语句 DaysOverDue=TODAY()-DateDue; 可以计算一本书应归还还剩余的期限。 Formats 打印日期数据时,还需要将数值换成日期,下面的 FORMAT 语句告诉 SAS 用 WEEKDATE17. 格式打印变量 BirthDate 。 FORMAT BirthDate WEEKDATE17.; 例子 图书馆有借书卡数据, Dates.dat ,包含持卡人姓名、出生日期、卡办理日期。 下面的代码读取数据,计算变量使用期限( expiredate ),使用期限为 3 年;变量 expirequarter 计算使用期限的四分之一,使用函数 QTR ()。接着用 IF 语句来判断一个卡是否为新卡,在 2003 年 1 月 1 日之后办理的,为新卡: 输出结果为: 注意 BirthDate 没有用日期格式。
个人分类: sas|0 个评论
分享 初级统计师已招到
luleiyan 2013-12-16 10:23
初级统计师已招到,多谢大家关注。 计划明年春天招聘一位SAS程序员,有兴趣的同学可以发简历到 leiyanlv@gmail.com . 我是部门主管不是猎头,简历发给我相当于跳过招聘部门,能够获得更多录用机会。 如果有求职意向就不要犹豫了:)
2 次阅读|0 个评论
分享 SAS 9.3 64位和32位下载地址非常快速
热度 2 lfg880433 2013-1-3 12:41
搜索了很久 终于找到了SAS 9.3 64位和32位下载地址。
51 次阅读|2 个评论
分享 通过示例学SAS(14)--宏(Macro)
wlnk 2012-9-28 09:34
1.一些内建宏变量 两个有用的宏变量分别是SYSDATE9和SYSTIME。前者告诉你日期,后者保存有时间。如 title "The Date is sysdate9 - the Time is systime"; proc print data=learn.test_scores noobs; run; 注意,宏变量只在引用在双引号,若在单引号下,并不会得到 解析。也就是说,在带有引号的文本中引用宏变量时,需要将这个文本字符串用双引号括起来。 2.以%LET赋值给宏变量 %let n = 3; data generate; do Subj = 1 to n; x = int(100*ranuni(0) + 1); output; end; run; title "Data Set with n Random Numbers"; proc print data=generate noobs; run; %LET放在数据步的前面。每次程序运行时,n被替换为3. 宏变量被定义后,就可以通过在其名称前使用来对其进行引用。 3.简单宏 宏以%MACRO开始,以%MEND结束。现在想修改上一个例程,使之能更通用。不仅能修改随机数的个数,还能改变开始值和结束值。代码如下 %macro gen(n,Start,End); data generate; do Subj = 1 to n; x = int((End - Start + 1)*ranuni(0) + Start); output; end; run; proc print data=generate noobs; title "Randomly Generated Data Set with n Obs"; title2 "Values are integers from Start to End"; run; %mend gen; 宏GEN有三个参数,分别为n,Start,End.为了产生4个从1到100的随机数,调用如下 %gen(4,1,100) 调用宏时,用一个%加宏名字就可以调用该宏。后面无需分号。 解析宏变量有一个需要值得注意的地方。假设有一段代码如下 %let prefix = abc; data prefix123; x = 3; run; 你的本意是产生一个名为Abc123的数据集。实际执行时却产生错误,SAS认为你要产生的数据集名为prefix123了。解决方法是在prefix后加一个点。如 %let prefix = abc; data prefix.123; x = 3; run; 4.通过宏变量在数据步之间传值   宏只在data步和proc步间起作用。如果想用数据步产生的信息值创建宏变量,以便于在后面的程序中使用。可以用到Symput和sysmget子程序。 例如,假设你已经用proc means计算了变量的平均值,现在想比较每个观测值与平均值的差异。示例如下 proc means data=learn.blood noprint; var RBC WBC; output out=means mean= M_RBC M_WBC; run; data _null_; set means; call symput('AveRBC',M_RBC); call symput('AveWBC',M_WBC); run; data new; set learn.blood(obs=5 keep=Subject RBC WBC); Per_RBC = RBC / AveRBC; Per_WBC = WBC / AveWBC; format Per_RBC Per_WBC percent8.; run; proc means产生一个名为Means的数据集,包含了M_RBC和M_WBC两个变量,分别表示RBC和WBC的平均值。 Data_NULL_步使用了SYMPUT,以把Data步的值赋给宏变量。不能使用%LET,因为不知道M_RBC和M_WBC的值。SYMPUTU的第一个参数是想创建的宏变量的名字,第二个参数是想赋给宏变量的值。一旦此步执行,两个宏变量将得到其平均值。 最后,介绍宏程序设计语句 %*        宏注释语句 %do 条件处理至一个匹配的%end语句 %do %until 重复循环直到条件为真 %do %while 重复循环 %global 创建全局宏变量  %if %then %else 条件执行语句 %input  为宏变量提供值 %let 创建宏变量 %macro 定义宏 %mend 结束宏定义 %macro-name 调用宏 %put 输出文件到log窗口 宏函数 %Eval 计算算术和逻辑表达式,整数格式 %sysevalf 计算算术和逻辑表达式,浮点格式 %length 返回自变量的长度 %Bquote 引用一个可分辨的值,不包括未处理的特殊符号和寄存器操作符。 %Nrbquote 引用一个可分辨的值,包括未处理的特殊符号和寄存器操作符。 %Nrquote 引用一个可分辨的值,包括和% %Nrstr 引用固定文本,包括%和 %Quote 引用一个除%和之外的可分辨值 %str 引用除%和之外的固定文本 %Superq 引用具有不确定变量值的宏变量 %Unquote 没有被引用
个人分类: SAS|5 次阅读|0 个评论

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2020-7-7 13:13