06-20-2024
nstdt
Quartz | Level 8
Member since
06-10-2014
- 74 Posts
- 32 Likes Given
- 0 Solutions
- 3 Likes Received
-
Latest posts by nstdt
Subject Views Posted 2450 04-04-2024 10:35 AM 2470 04-04-2024 09:37 AM 2556 04-03-2024 06:46 PM 3537 02-21-2024 01:45 PM 3564 02-21-2024 12:45 PM 3724 02-19-2024 07:14 PM 3724 02-19-2024 07:13 PM 3734 02-19-2024 07:09 PM 3748 02-19-2024 07:06 PM 3794 02-19-2024 06:26 PM -
Activity Feed for nstdt
- Liked Re: Simulating from a Beta distribution with specified skewnewss and kurtosis for Rick_SAS. 06-20-2024 03:59 PM
- Posted Re: Simulating from a Beta distribution with specified skewnewss and kurtosis on SAS/IML Software and Matrix Computations. 04-04-2024 10:35 AM
- Posted Re: Simulating from a Beta distribution with specified skewnewss and kurtosis on SAS/IML Software and Matrix Computations. 04-04-2024 09:37 AM
- Liked Re: Simulating from a Beta distribution with specified skewnewss and kurtosis for Rick_SAS. 04-04-2024 09:25 AM
- Tagged Simulating from a Beta distribution with specified skewnewss and kurtosis on SAS/IML Software and Matrix Computations. 04-03-2024 06:54 PM
- Tagged Simulating from a Beta distribution with specified skewnewss and kurtosis on SAS/IML Software and Matrix Computations. 04-03-2024 06:54 PM
- Posted Simulating from a Beta distribution with specified skewnewss and kurtosis on SAS/IML Software and Matrix Computations. 04-03-2024 06:46 PM
- Liked Re: Use ODS Tagsets and macrovariables to print multiple datasetes to Excel for PaigeMiller. 02-21-2024 03:40 PM
- Liked Re: Use ODS Tagsets and macrovariables to print multiple datasetes to Excel for Tom. 02-21-2024 03:39 PM
- Posted Re: Use ODS Tagsets and macrovariables to print multiple datasetes to Excel on SAS Programming. 02-21-2024 01:45 PM
- Liked Re: Use ODS Tagsets and macrovariables to print multiple datasetes to Excel for PaigeMiller. 02-21-2024 01:41 PM
- Posted Re: Use ODS Tagsets and macrovariables to print multiple datasetes to Excel on SAS Programming. 02-21-2024 12:45 PM
- Liked Re: Use ODS Tagsets and macrovariables to print multiple datasetes to Excel for Patrick. 02-20-2024 08:15 AM
- Posted Re: Use ODS Tagsets and macrovariables to print multiple datasetes to Excel on SAS Programming. 02-19-2024 07:14 PM
- Posted Re: Use ODS Tagsets and macrovariables to print multiple datasetes to Excel on SAS Programming. 02-19-2024 07:13 PM
- Liked Re: Use ODS Tagsets and macrovariables to print multiple datasetes to Excel for PaigeMiller. 02-19-2024 07:13 PM
- Posted Re: Use ODS Tagsets and macrovariables to print multiple datasetes to Excel on SAS Programming. 02-19-2024 07:09 PM
- Liked Re: Use ODS Tagsets and macrovariables to print multiple datasetes to Excel for SASKiwi. 02-19-2024 07:09 PM
- Posted Re: Use ODS Tagsets and macrovariables to print multiple datasetes to Excel on SAS Programming. 02-19-2024 07:06 PM
- Posted Use ODS Tagsets and macrovariables to print multiple datasetes to Excel on SAS Programming. 02-19-2024 06:26 PM
-
Posts I Liked
Subject Likes Author Latest Post 3 7 1 1 1 -
My Liked Posts
Subject Likes Posted 1 02-18-2023 04:29 PM 2 10-21-2016 06:12 AM
04-04-2024
10:35 AM
Thank you @Rick_SAS , for your patient answer and advice! Yes, the main problem is making sure the Skew and Kurtosis match up with each other , withing a legitimate distribution.
Very kind of you to help!
... View more
04-04-2024
09:37 AM
Thank you, @Rick_SAS !
Yes, I suppose I have to find a nonlinear solver to get me the shape values a and b, given Skew and Kurtosis.
Not sure if I need a different post but what if I choose to go with a mixture of Normalsan like in the image below, but truncated on the left? I am going for something like below, but on a bounded interval (on one side only). I am looking to try cross different Skew and Kurtosis values : Skew in 0 to 3 and Kurt in (3,5,7)
(From Allison J. Ames, Brian C. Leventhal & Nnamdi C. Ezike (2020) Monte Carlo Simulation in Item Response Theory Applications Using SAS, Measurement: Interdisciplinary Research and Perspectives, 18:2, 55-74, DOI: 10.1080/15366367.2019.1689762 https://doi.org/10.1080/15366367.2019.1689762 )
I found this from your blog:
https://blogs.sas.com/content/iml/2019/04/29/normal-mixture-distribution-sas.html and Implement the truncated normal distribution in SAS - The DO Loop ?
Sorry, too many questions. Any advice would help get me started. Thank you again!
... View more
04-03-2024
06:46 PM
Hi,
I am trying to generate a single column of data (length N=250,1000, 2000), from a Beta distribution with specified skewness and kurtosis (I want a range of skewness and kurtosis: skew = 0,1,2 and kurt = 3,5,7). Given values for Skew and Kurt, I am not able to back-solve for the Beta shape parameters A and B. Is there a formula to go from Skew and Kurt to A and B?
How can I get the data I want? I found this post here which is similar to my problem:
https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Generating-a-non-normal-distribution-with-specified-skewness-and/td-p/442143
Should I just use the RandFleishman code and modify the FLFUNC and FLDERIV functions be the Beta function and it's first derivative? I am not sure how to go about this.
/* Newton's method to find roots of a function.
You must supply the FLFUNC and FLDERIV functions
that compute the function and the Jacobian matrix.
Input: x0 is the starting guess
optn[1] = max number of iterations
optn[2] = convergence criterion for || f ||
Output: x contains the approximation to the root */
start Newton(x, x0, optn);
maxIter = optn[1]; converge = optn[2];
x = x0;
f = FLFunc(x);
do iter = 1 to maxIter while(max(abs(f)) > converge);
J = FLDeriv(x);
delta = -solve(J, f); /* correction vector */
x = x + delta; /* new approximation */
f = FLFunc(x);
end;
/* return missing if no convergence */
if iter > maxIter then x = j(nrow(x0),ncol(x0),.);
finish Newton;
Are there otehr modifications I need to make to the RandFleishman code?
I am new to simulating data.
@Rick_SAS or others, please help! Thank you.
... View more
- Tags:
- beta
- simulation
02-21-2024
01:45 PM
Thanks, this comes closest to my requirements.
I originally was working with datasets with common column names, but later realised I may have to generalize this to when there are no common column names.
I can, however, create a common variable - a row number column. Or, it would seem, from your reply and @PaigeMiller , I can make the BY variable in PROC Excel just be the datasetname (where datasetname is the data set that combines all the original datasets).
Thanks again.
... View more
02-21-2024
12:45 PM
Thanks for the example. Quick followup - what if I have multiple datasets that need to output to different Excel sheets? So, my data is in different datasets - dat1,dat2,...,datN and each of these need to output to their own separate tab in one single Excel file. I can't think of a single common BY variable (except perhaps the Row Number). How could I modify your example code - any suggestions would help!
... View more
02-19-2024
07:14 PM
What I meant is that there are several different datasets to export. How can I manage this with a single BY group ? The column names are the same but the name of each dataset is different.
... View more
02-19-2024
07:13 PM
Thanks! Do you have a small example to share? I would like to avoid using a Macro if possible!
... View more
02-19-2024
07:09 PM
Yes, thanks! I was using "PUT" instead of "LET"!
... View more
02-19-2024
07:06 PM
Here is the Log:
2505 dm "log; clear; ";
2506 dm 'odsresults; clear';
2507 options mprint;
2508 /* */
2509 %macro getBetas();
2510 %let varnamelist = SLSS3 PANASn3 PANASp3 /*PANASpP3 PANASnP3 CES3 CHSa3 CHSp3 CHStot3 CASSSC3
2510! CASSSP3 CASSST3*/ ;
2511 %put &varnamelist;
2512 %let end=%sysfunc(countw(&varnamelist));
2513 %put &end;
2514 %do i = 1 %to &end;
2515 %put out= %scan(&varnamelist., &i, " ");
2516 proc print data=EstCovWithBL_&out.;
2517 run;
2518 %end;
2519 %mend;
2520
2521 ods tagsets.excelxp style=sasweb
2522 file="C:\Users\radhi\OneDrive - University of Delaware - o365\Desktop\Dr Suldo
2522! IES\estbetas.xls";
NOTE: Writing TAGSETS.EXCELXP Body file: C:\Users\radhi\OneDrive - University of Delaware -
o365\Desktop\Dr Suldo IES\estbetas.xls
NOTE: This is the Excel XP tagset (Compatible with SAS 9.1.3 and above, v1.131, 04/23/2015). Add
options(doc='help') to the ods statement for more information.
2523 %getBetas;
SLSS3 PANASn3 PANASp3
3
out= SLSS3
NOTE: Writing HTML Body file: sashtml4.htm
WARNING: Apparent symbolic reference OUT not resolved.
NOTE 137-205: Line generated by the invoked macro "GETBETAS".
1 proc print data=EstCovWithBL_&out.; run;
-
22
ERROR 22-322: Syntax error, expecting one of the following: ;, (, BLANKLINE, CONTENTS, DATA,
DOUBLE, GRANDTOTAL_LABEL, GRANDTOT_LABEL, GRAND_LABEL, GTOTAL_LABEL, GTOT_LABEL,
HEADING, LABEL, N, NOOBS, NOSUMLABEL, OBS, ROUND, ROWS, SPLIT, STYLE, SUMLABEL,
UNIFORM, WIDTH.
NOTE: Line generated by the invoked macro "GETBETAS".
1 proc print data=EstCovWithBL_&out.; run;
-
200
ERROR 200-322: The symbol is not recognized and will be ignored.
WARNING: Apparent symbolic reference OUT not resolved.
ERROR: File WORK.ESTCOVWITHBL_.DATA does not exist.
MPRINT(GETBETAS): proc print data=EstCovWithBL_&out. run;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.43 seconds
cpu time 0.15 seconds
out= PANASn3
WARNING: Apparent symbolic reference OUT not resolved.
NOTE 137-205: Line generated by the invoked macro "GETBETAS".
3 proc print data=EstCovWithBL_&out.; run;
-
22
ERROR 22-322: Syntax error, expecting one of the following: ;, (, BLANKLINE, CONTENTS, DATA,
DOUBLE, GRANDTOTAL_LABEL, GRANDTOT_LABEL, GRAND_LABEL, GTOTAL_LABEL, GTOT_LABEL,
HEADING, LABEL, N, NOOBS, NOSUMLABEL, OBS, ROUND, ROWS, SPLIT, STYLE, SUMLABEL,
UNIFORM, WIDTH.
NOTE: Line generated by the invoked macro "GETBETAS".
3 proc print data=EstCovWithBL_&out.; run;
-
200
ERROR 200-322: The symbol is not recognized and will be ignored.
WARNING: Apparent symbolic reference OUT not resolved.
ERROR: File WORK.ESTCOVWITHBL_.DATA does not exist.
MPRINT(GETBETAS): proc print data=EstCovWithBL_&out. run;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
out= PANASp3
WARNING: Apparent symbolic reference OUT not resolved.
NOTE 137-205: Line generated by the invoked macro "GETBETAS".
5 proc print data=EstCovWithBL_&out.; run;
-
22
ERROR 22-322: Syntax error, expecting one of the following: ;, (, BLANKLINE, CONTENTS, DATA,
DOUBLE, GRANDTOTAL_LABEL, GRANDTOT_LABEL, GRAND_LABEL, GTOTAL_LABEL, GTOT_LABEL,
HEADING, LABEL, N, NOOBS, NOSUMLABEL, OBS, ROUND, ROWS, SPLIT, STYLE, SUMLABEL,
UNIFORM, WIDTH.
NOTE: Line generated by the invoked macro "GETBETAS".
5 proc print data=EstCovWithBL_&out.; run;
-
200
ERROR 200-322: The symbol is not recognized and will be ignored.
WARNING: Apparent symbolic reference OUT not resolved.
ERROR: File WORK.ESTCOVWITHBL_.DATA does not exist.
MPRINT(GETBETAS): proc print data=EstCovWithBL_&out. run;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
2524 ods tagsets.excelxp close;
... View more
02-19-2024
06:26 PM
I have multiple datasets with similar names : EstOut_varname
I am trying to use ODS TAGSETS to output them all to Excel. I am also using a Macro function to loop over the similarly names datasets, like below. However, inside Proc Print, the macrovariable isn't dereferencing the way I thought it would. Please advice - thanks for any help!
ods tagsets.excelxp style=sasweb
file="C:\Users\radhi\Desktop\estvars.xls";
%getBetas;
ods tagsets.excelxp close;
/*** Macro to Loop over existing Datsets that I am trying to output to Excel ***/
/*** The Datasetes are all named EstVar_varname ***/
%macro getBetas();
%let varnamelist = varn1 varn2 varn3 ;
%put &varnamelist;
%let end=%sysfunc(countw(&varnamelist));
%put &end;
%do i = 1 %to &end;
%put out= %scan(&varnamelist., &i, " ");
proc print data=EstVar_&out.;
run;
%end;
%mend;
However, SAS does not dereference EstVar_&out. and does not recognise the &out :
proc print data=EstVar_&out.; run; - 200 ERROR 200-322: The symbol is not recognized and will be ignored.
... View more
11-09-2023
11:52 AM
I need to search through the 15 variables of a dataset for a specific substring (the word "None"). When I use the code below for just one variable, I can get the results I want. However, when I try to use a Macro to loop through all 15 variables, the code does not detect the word None - although there are no errors in the log.
Code without macro (just one variable):
data countvar;
set indata;
length word $ 25;
searchstr = var_1; ** Count occurrences of substring None None_flag=0; do i=1 to countw(searchstr); word=scan(searchstr,i); if findw("None",strip(word),'i')>=1 then do; None_flag=1; leave; end; end; run;
Now when I try to create a macrovariable list of all the variables in the dataset 'Indata' inside 'list' and pass the above function into a macro "loopit", the code runs without errors but fails to detect the substring "None" - the variable None_flag is zero for all observations in the dataset.
%macro loopit(list);
data countvar1;
set Dat_q3_wide;
%do i = 1 %to %sysfunc(countw(&list.));
%let word = %scan(&list., &i.);
None_flag=0;
%if %sysfunc(findw(None,strip(&word),ii))>=1 %then %do;
None_flag=1;
%end;
%end;
run;
%mend loopit;
%let list = Var_1 Var_2 Var_3 Var_4;
%loopit(list=&list)
Here is some sample data:
ID
Var_1
Var_2
Var_3
11
None(0%)
Nearly all(100%)
None(0%)
12
Nearly all(100%)
None(0%)
None(0%)
13
None(0%)
Some (50%)
Nearly all(100%)
... View more
05-02-2023
03:31 PM
Thanks so much! The values per se of the 'time' variable aren;t important - I'm just interested in the correlation over time within a Phase for a specific subject.
... View more
05-02-2023
12:31 PM
I have an ABAB design with repeated time observations within a single phase (A - baseline phase, B- treatment phase. Each subject gets both phases, repeated many times, about 10 to 30 per subject per phase). There are 9 subjects in total. What is the best wyay to model this data using a mixed model structure - I was trying to see if each subject is a 'unit', and it makes sense to have random effects for the Intercept and maybe the Phase for each subject. But there is also the correlation amongst 'outcome' scores for a specific subject within a Phase - surely that has to be something like AR(1) or CS?
Here is data from one single subject 'case A1':
case phase time outcome
case A1 1 1 7
case A1 1 2 9
case A1 1 3 8
case A1 1 4 6
case A1 1 5 7
case A1 1 6 4
case A1 1 7 5
case A1 1 8 10
case A1 1 9 2
case A1 1 10 0
case A1 2 15 3
case A1 2 16 8
case A1 2 17 8
case A1 2 18 6
case A1 2 19 10
case A1 2 20 10
case A1 2 21 10
case A1 2 22 8
case A1 2 23 3
case A1 2 24 4
... View more
05-01-2023
03:23 PM
Thanks so much for the reply! I will try increasing the interations. Meanwhile, I want to know how I can get G-side effects for the Intercept in the model shown below(I have specified a random Intercept - but number of columns in Z=0 per the SAS output - what is wrong with my syntax???):
title "Model with only R-side CS errors";
proc glimmix data=model_dat2;
class case phase;
model y = flag_2 flag_3 flag_4/solution dist=binomial link=logit cl;
random Intercept/sub=case type=cs residual;
run;
OUTPUT:
Dimensions
R-side Cov. Parameters 2
Columns in X 4
Columns in Z per Subject 0
Subjects (Blocks in V) 9
Max Obs per Subject 59
... View more
04-29-2023
11:03 PM
I have repeated (over time) data on 9 subjects, subjected to two types of 'Phases' - Treatment and Control, similar to below table (for just 2 subjects - second columns is outcome Y - in count format). There are a total of 4 phases, alternating in an ABAB design.
A
10
6
5
B
20
15
7
I converted the outcomes to proportions and am trying to fit a mixed effects logit model. The first model only has 2 random effects - Intercept and Phase :
title "Basic logit model";
proc glimmix data=lambert2;
class case;
model y = phase/solution dist=binomial link=logit cl;
random Intercept phase/sub=case;
run;
OUTPUT:
Dimensions
G-side Cov. Parameters 2
Columns in X 2
Columns in Z per Subject 2
Subjects (Blocks in V) 9
Max Obs per Subject 59
Estimated G matrix is not positive definite.
Fit Statistics
-2 Res Log Pseudo-Likelihood 1847.10
Generalized Chi-Square 241.97
Gener. Chi-Square / DF 0.53
Covariance Parameter Estimates
Cov Parm Subject Estimate Standard
Error
Intercept case 0 .
phase case 0 .
Q1: In the Output Dimensions Table, which are the columns in X and which variables go in Z? Are both Intercept and Phase random errors considered G-side parameters? Both covariance parameters are 0 - what does this mean?
Next, I dummy coded the Phase variable to reflect the ABAB design (with three dummies ) and re-ran the Mixed Logit model with what I thought were R-side errors using compound symmetry (I mean that I am modeling the within subject correlation using compound symmetry) as below:
title "Model with only R-side CS errors";
proc glimmix data=model_dat2;
class case phase;
model y = flag_2 flag_3 flag_4/solution dist=binomial link=logit cl;
random Intercept/sub=case type=cs residual;
run;
OUTPUT:
Dimensions
R-side Cov. Parameters 2
Columns in X 4
Columns in Z per Subject 0
Subjects (Blocks in V) 9
Max Obs per Subject 59
Fit Statistics
-2 Res Log Pseudo-Likelihood 1718.07
Generalized Chi-Square 141.32
Gener. Chi-Square / DF 0.31
Covariance Parameter Estimates
Cov Parm Subject Estimate Standard
Error
CS case 0.006232 0.006211
Residual 0.3099 0.02071
For the model with the ABAB phase dummies as above, why is number of columns in Z=0? I have specified "Intercept" as a random effect (at least that's my intention)? Is my syntax incorrect? Is the variance of the Intercept not considered a G-side random effect?
Then I tried running the syntax below but this does not converge:
title "Model with only R-side CS errors -with Intercept";
proc glimmix data=model_dat2;
class case phase;
model y = flag_2 flag_3 flag_4/solution dist=binomial link=logit cl;
/*random Intercept flag_2 flag_3 flag_4/sub=case;*/
random phase/sub=case type=cs residual;
random intercept/sub =case;
run;
OUTPUT:
Dimensions
G-side Cov. Parameters 1
R-side Cov. Parameters 2
Columns in X 4
Columns in Z per Subject 1
Subjects (Blocks in V) 9
Max Obs per Subject 59
Did not converge.
Covariance Parameter Estimates
Cov Parm Subject Estimate Standard
Error
Intercept case 0.2221 .
CS case -0.03368 .
Residual 0.3067 .
How do I interpret the above results?
... View more