-
Latest posts by n6
Subject Views Posted 745 02-27-2025 07:38 PM 440 11-18-2024 02:07 PM 2059 06-13-2024 09:21 AM 2216 06-12-2024 04:43 PM 2261 06-12-2024 04:34 PM 2270 06-12-2024 04:15 PM 2311 06-12-2024 03:31 PM 1217 06-11-2024 11:29 PM 1236 06-11-2024 10:29 PM 1314 06-11-2024 07:26 PM -
Activity Feed for n6
- Posted Is there a limited, cheaper version of SAS? on SAS Programming. 02-27-2025 07:38 PM
- Posted proc fmm on Statistical Procedures. 11-18-2024 02:07 PM
- Posted Re: Putting x-axis labels on two lines on SAS Programming. 06-13-2024 09:21 AM
- Posted Re: Putting x-axis labels on two lines on SAS Programming. 06-12-2024 04:43 PM
- Posted Re: Putting x-axis labels on two lines on SAS Programming. 06-12-2024 04:34 PM
- Posted Re: Putting x-axis labels on two lines on SAS Programming. 06-12-2024 04:15 PM
- Posted Putting x-axis labels on two lines on SAS Programming. 06-12-2024 03:31 PM
- Got a Like for Re: Format getting assign in a DO LOOP even though initial DO condition isn't satisfied. 06-12-2024 09:13 AM
- Posted Re: Format getting assign in a DO LOOP even though initial DO condition isn't satisfied on SAS Programming. 06-11-2024 11:29 PM
- Posted Re: Format getting assign in a DO LOOP even though initial DO condition isn't satisfied on SAS Programming. 06-11-2024 10:29 PM
- Posted Re: Format getting assign in a DO LOOP even though initial DO condition isn't satisfied on SAS Programming. 06-11-2024 07:26 PM
- Posted Format getting assign in a DO LOOP even though initial DO condition isn't satisfied on SAS Programming. 06-11-2024 04:36 PM
- Posted Is there a way to tell SAS to not retain data when using arrays? on SAS Programming. 03-06-2022 11:00 PM
- Posted Re: proc import with a .txt file with a | delimiter on SAS Programming. 11-16-2021 01:19 PM
- Posted proc import with a .txt file with a | delimiter on SAS Programming. 11-16-2021 12:43 PM
- Posted Re: Why do my settings go away when I close SAS. on Administration and Deployment. 07-19-2021 03:13 PM
- Posted Re: Why do my settings go away when I close SAS. on Administration and Deployment. 07-19-2021 02:59 PM
- Posted Re: Why do my settings go away when I close SAS. on Administration and Deployment. 07-19-2021 02:54 PM
- Posted Re: Why do my settings go away when I close SAS. on Administration and Deployment. 07-19-2021 01:48 PM
- Posted Re: Why do my settings go away when I close SAS. on Administration and Deployment. 07-19-2021 11:51 AM
-
Posts I Liked
Subject Likes Author Latest Post 1 -
My Liked Posts
Subject Likes Posted 2 06-11-2024 11:29 PM 2 11-15-2019 12:34 PM
02-27-2025
07:38 PM
I'm a longtime SAS user and I'm going to retire in about five years. I have SAS through my job and I'm allowed to use it for personal use. I don't use it much for personal use, but I do use it some for things and I like it a lot. But I don't use SAS's extensive capabilities. I just use the datastep, maybe procs freq, means, print, and simple stuff like that.
When I retire, my SAS is going to go away. I can live without proc mixed and all that stuff since I'll no longer be doing serious statistical analyses by then, but I sure am going to miss the datastep and those other things to do small daily projects that I like to do. I'd sure like it if someone told me there was a real stripped down version of SAS I could buy for maybe $100-200 per year. Because otherwise I'd have to pay thousands of dollars per year for full SAS and then not use 99.9% of it, and I'm not going to do that. But from my research I'm guessing you'll say, sorry, there is no stripped down version of SAS that costs way less than full SAS.
If that's the case, any suggestions on what I can use instead? I know R a little and I like SAS way better. I find R a little annoying. But I guess I'll just break down and learn it better and use it some in retirement since my only alternative seems to be using nothing at all.
Thanks for reading. Any thoughts or info is appreciated.
... View more
11-18-2024
02:07 PM
I'm doing a Zero-Truncated Negative Binomial model in proc fmm. (I'm also considering a Zero-Truncated Poisson although I think we have overdispersion.)
One general question is this. From what I read diving the Pearson Statistic by the degrees of freedom tells you whether there is overdispersion or underdispersion. A ways < 1 implies underdispersion and a ways > 1 implies overdispersion.
Okay, that's one thing. But more specifically, in one model I get the following message in the output:
"Optimization routine cannot improve the function value."
And this same model does not give me results. Any idea what this is? It kinda feels like the "Algorithm did not converge" message I sometimes get in other SAS procs.
Any info is appreciated. Thanks in advance.
... View more
06-12-2024
04:43 PM
That said, if worse comes to worse I could make a character variable and use it for the x-axis but it would be a pain since I'll be generating a lot of graphs.
... View more
06-12-2024
04:34 PM
FitPolicy looks promising but the problem is that I don't have a text string that goes on the x-axis, like in your example, and instead I have a numeric variable (1 thru 7) that has a format and it is the formatted values that are too long and that I'd like to go on separate rows. Any remedy for that?
... View more
06-12-2024
04:15 PM
I'm using proc sgplot. I've never heard of FITPOLICY the other person mentioned. I'll look into it. I'll be making a bunch of plots so something that is general would be helpful. If it was just one or two then I'd consider things like reducing the font but I don't think that's feasible when making a bunch of them.
... View more
06-12-2024
03:31 PM
I'm generating a plot. On the x-axis is a variable with numbers 1 thru 7. But it has a format, so the plot shows the formatted names instead of 1 thru 7.
But the problem is that using the words on the x-axis makes it too long. So instead of using the words for all of 1 thru 7, it'll use just the names for 1, 3, 5 and 7 and leave out the ones for 2, 4 and 6.
It seems to me that one way around this would be to put the words on two lines instead of one. So instead of this being below the x-axis
Operating Equipment
we could put this
Operating
Equipment
It would take up two lines in the up and down direction but it would take up less space left to right and thus there would be room for all seven formatted values instead of just those for 1, 3, 5 and 7.
Is that possible? What do you think? Any help is appreciated. I can attach the code if you like but I have a feeling that will not be necessary in this case since it's pretty straightforward.
... View more
06-11-2024
11:29 PM
2 Likes
That did it. My root problem is that I didn't know that format assignments were just done in datastep without regard to whether they were in a if-then-do loop.
Also, I was trying to use code like
if &X_VAR = "NatInj_Hand" then do;
when instead I should have been using code like
%if &X_VAR = NatInj_Hand %then %do
So that's that. Although I've done a lot of macro coding, I haven't used %if and %then much so that was my problem, as well as the aforementioned fact that I didn't know that formats were assigned even if they were in a do loop.
Thanks to all for the help.
... View more
06-11-2024
10:29 PM
I'm not sure what you're saying about informats but I have the following proc format earlier in the program that defines the formats that I refer to in the macro. Since the macro argument I pass is NatInj_Hand, I should see the words below for that format, but instead I see words for the other formats (or numbers when it runs out of what it thinks should be the formats).
Also note that the NatInj_Hand variable exists before I call the macro and it is a binary variable that I use as the response variable in the proc logistic. The newly created variable in the macro is NatInj_Hand_v and it contains values 1 thru 8 and it is supposed to have the formats for NatInj_Hand below, but the proc print at the end of my macro shows that it does not, which is the problem. I'm pretty sure I could get around this problem by being inelegant and if I can't figure it out much longer I may do that, but for now, I'll keep trying. The code I attached has three variables for now in the "X_VAR" section but if I can fix my current problem it's going to have a lot more.
proc format; value NatInj_Hand 1 = 'Amputation' 2 = 'Burns' 3 = 'Crushing' 4 = 'Lac/Punc' 5 = 'Frac/Chip' 6 = 'Other inj' 7 = 'Sprain/Strain' 8 = 'Contusion/Bruise' ; 1 = 'Op Equip' 2 = 'Handling' 3 = 'Weld/Grind' 4 = 'Mach Maint' 5 = 'Hand (No Pow)' 6 = 'Hand (Power)' 7 = 'Walk/Run' 8 = 'Other' 9 = 'Roofbolt' ; value SubUnit 1 = 'Underground' 2 = 'Mill / Prep Plant' 3 = 'Surface' ; value Sector 1 = 'Coal' 2 = 'Sand/Gravel' 3 = 'Stone' 4 = 'Metal' 5 = 'NonMetal' ; run;
... View more
06-11-2024
07:26 PM
The macro code is below with the macro call below that. The code is lined up and beautiful and easy to read in my program editor but it is hard to read below. If there's a way to make it easier to read for you then please let me know.
The first part of the macro is a proc freq, then a proc logistic that creates a dataset, but you can skip past that and go to the subsequent data step, where is uses that dataset and which is where the problem is.
In my output window, the proc print at the end shows that it's giving the wrong result. In the real macro there is yet more code below that but that's not the point, so I just put %MEND; right after the proc print. And there is no error in my log, although I can post it if you like, but I'm trying not to overwhelm you. My code runs without error but it just gives a result that I don't understand.
The chunk from "TAKE CARE OF X_VAR - START" to "TAKE CARE OF X_VAR - END" is where the problem is so you don't have to look at the stuff after that. The 2nd argument in the macro is x_var. The argument in the macro call that corresponds to that is NatInj_Hand. The if-then-do loop for NatInj_Hand comes first and creates a variable named NatInj_Hand_v and assigns a format to it.
But in the proc print at the end, the variable NatInj_v has a different format assigned to it. It has the format assigned in the if-then-do loop for Sector, which is the last of the three. Or if I comment that format assignment out, then it has the one for MineAct_Hand, which is the second of the three. Or if I comment both of those format assignments out, only then does it have the appropriate format assignment of the on in the NatInj_Hand if-then-do loop.
I hope this isn't too much. If there's anything I can do to make it easier or any questions I can answer then let me know.
%MACRO IMP (bodypart, x_var, x_var_ref, x_levels, group_var, group_var_ref); options mprint; proc freq data=AI_Use; tables &BODYPART.Inj * &X_VAR * &GROUP_VAR / nopct norow; run; ods select ModelInfo NObs ResponseProfile; proc logistic data=AI_Use; title "THIS HAS COVARIABLES &X_VAR AND &GROUP_VAR"; class &X_VAR (ref="&X_VAR_REF") &GROUP_VAR (ref="&GROUP_VAR_REF") / param=ref; model &BODYPART.Inj = &X_VAR &GROUP_VAR &X_VAR * &GROUP_VAR / clodds = wald; oddsratio &X_VAR; ods output OddsRatiosWald = &BODYPART._&X_VAR._&GROUP_VAR; run; proc print data=&BODYPART._&X_VAR._&GROUP_VAR; title "&BODYPART._&X_VAR._&GROUP_VAR"; run; data &BODYPART._&X_VAR._&GROUP_VAR.2; set &BODYPART._&X_VAR._&GROUP_VAR; *********************************************************************************; ************************* TAKE CARE OF X_VAR -- START *************************; *********************************************************************************; %LET X = "&X_VAR"; if &X = "NatInj_Hand" then do; if find (Effect, "&X_VAR_REF") ne 0 then do; if find (Effect, 'Amputation/Enucleation' ) ne 0 then &X_VAR._v = 1; if find (Effect, 'Burns' ) ne 0 then &X_VAR._v = 2; if find (Effect, 'Crushing' ) ne 0 then &X_VAR._v = 3; if find (Effect, 'Cut/Laceration/Puncture') ne 0 then &X_VAR._v = 4; if find (Effect, 'Fracture/Chip' ) ne 0 then &X_VAR._v = 5; if find (Effect, 'Other injury' ) ne 0 then &X_VAR._v = 6; if find (Effect, 'Sprain/Strains' ) ne 0 then &X_VAR._v = 7; * if find (Effect, 'Contusion/Bruise' ) ne 0 then &X_VAR._v = 8; label &X_VAR._v = 'Nature of Injury'; format &X_VAR._v NatInj_Hand.; end; end; if &X = "MineAct_Hand" then do; if find (Effect, "&X_VAR_REF") ne 0 then do; if find (Effect, 'Operating Equipment' ) ne 0 then &X_VAR._v = 1; if find (Effect, 'Handling Material' ) ne 0 then &X_VAR._v = 2; if find (Effect, 'Welding/Grinding' ) ne 0 then &X_VAR._v = 3; if find (Effect, 'Machine Maint./Repair)' ) ne 0 then &X_VAR._v = 4; if find (Effect, 'Hand tools (Not Powered)') ne 0 then &X_VAR._v = 5; if find (Effect, 'Hand tools (Powered)' ) ne 0 then &X_VAR._v = 6; if find (Effect, 'Walking/Running' ) ne 0 then &X_VAR._v = 7; if find (Effect, 'Other' ) ne 0 then &X_VAR._v = 8; * if find (Effect, 'Roofbolting' ) ne 0 then &X_VAR._v = 9; label &X_VAR._v = 'Mine Worker Activity'; format &X_VAR._v MineAct_Hand.; end; end; if &X = "Sector" then do; if find (Effect, "&X_VAR_REF") ne 0 then do; if find (Effect, '1 - Coal' ) ne 0 then &X_VAR._v = 1; if find (Effect, '5 - Sand/Gravel') ne 0 then &X_VAR._v = 2; if find (Effect, '6 - Stone' ) ne 0 then &X_VAR._v = 3; if find (Effect, '8 - Metal' ) ne 0 then &X_VAR._v = 4; * if find (Effect, '7 - Nonmetal' ) ne 0 then &X_VAR._v = 5; label &X_VAR._v = 'Sector'; format &X_VAR._v Sector.; end; end; *********************************************************************************; ************************* TAKE CARE OF X_VAR -- END *************************; *********************************************************************************; *********************************************************************************; *********************** TAKE CARE OF GROUP_VAR -- START ************************; *********************************************************************************; %LET GROUP = "&GROUP_VAR"; if &GROUP = "SubUnit3" then do; if find (Effect, 'A-Underground' ) ne 0 then &GROUP_VAR._v = 1; if find (Effect, 'C-Mills/Prep Plants') ne 0 then &GROUP_VAR._v = 2; if find (Effect, 'B-Surface' ) ne 0 then &GROUP_VAR._v = 3; label &GROUP_VAR._v = 'SubUnit3'; format &GROUP_VAR._v SubUnit.; end; else if &GROUP = "Sector" then do; if find (Effect, "&X_VAR_REF") ne 0 then do; if find (Effect, '1 - Coal' ) ne 0 then &GROUP_VAR._v = 1; if find (Effect, '5 - Sand/Gravel') ne 0 then &GROUP_VAR._v = 2; if find (Effect, '6 - Stone' ) ne 0 then &GROUP_VAR._v = 3; if find (Effect, '8 - Metal' ) ne 0 then &GROUP_VAR._v = 4; if find (Effect, '7 - Nonmetal' ) ne 0 then &GROUP_VAR._v = 5; label &GROUP_VAR._v = 'Sector'; format &GROUP_VAR._v Sector.; end; end; *********************************************************************************; *********************** TAKE CARE OF GROUP_VAR -- END ************************; *********************************************************************************; if &X_VAR._v ne . and &GROUP_VAR._v ne . then output; run; proc print data=&BODYPART._&X_VAR._&GROUP_VAR.2; title "ODDS RATIO OF HAVING A &BODYPART INJURY AS OPPOSED TO A NON-&BODYPART INJURY"; var &X_VAR._v &GROUP_VAR._v OddsRatioEst LowerCL UpperCL; run;
%MEND;
Here is the macro call.
%IMP (Hand, NatInj_Hand , Contusion/Bruise, 7, SubUnit3, B-Surface );
... View more
06-11-2024
04:36 PM
The code below isn't my exact code but it accurately illustrates the problem and is much simpler.
I have a macro named ABC with the argument BP_VAR. "BP" stands for "Body Part" and the values I can specify for BP_VAR are Arm, Leg and Head.
Inside the macro, there is a datastep and inside it I had code like this.
If &BP_VAR = "Arm" then do;
... some statements...
end;
And there is similar code for Leg and Head. But it wouldn't work so I found a way around it, although if you have comments on why the above didn't work then I'd be interested to hear it.
But here is the way I got around it, with a longer example to get to the meat of my question. The formats abc, def and ghi referred to below have already been defined. This code is from inside the macro.
%LET BP = "&BP_VAR";
if &BP = "Arm" then do;
...some assignment statements to create a new variable &BP.2;
format &BP.2 abc.;
end;
if &BP = "Leg" then do;
...some assignment statements to create a new variable &BP.2;
format &BP.2 def.;
end;
if &BP = "Head" then do;
...some assignment statements to create a new variable &BP.2;
format &BP.2 ghi;
end;
So as you can see, when the body part of interest is Arm, I want it to go to the Arm section of the macro and make a new variable named Arm2, makes some assignments for it, then assign a format to it. And then go on to do some other stuff that is not relevant to the current problem.
And I want to do the same when the body part of interest is Leg. And again when the body part of interest is Head.
Okay, so here is the problem. Say the body part is Arm. The if-then condition is satisfied in the first section and it creates the new variable and assigns the format abc to it. Neither of the other two if-then conditions are satisfied so it shouldn't even get into those it-then-do loops.
And yet when I run the code as listed, the format for the newly created variable Arm2 is ghi (the one in the 3rd if-then-do group). If I comment out the format assignment in the 3rd group, then the format for the new variable is def (the one in the 2nd if-then-do group).
IOW, it uses the last non-commented out format assignment statement there is even if it's inside a if-then-do group that does not get executed. I even put "put = 'gets here';" code inside the if-then-do group that I don't think is getting executed, and indeed it is not getting executed because the "gets here" message does not show up in the log. And yet somehow the format assignment in that if-then-do group does get executed.
Any idea on what's happening? Thanks in advance.
... View more
03-06-2022
11:00 PM
I haven't used arrays recently but I would've sworn that data in them didn't retain. But then I wrote some code using arrays and was getting unexpected answers and I finally figured out it was because the data was being retained when it went to the next observation. It took me awhile to figure it out because I didn't even consider that a possibility because I was so sure that that wasn't how arrays work in SAS.
So the question is, is there a simple way to tell SAS to not retain data when I'm using arrays? Any info is appreciated.
... View more
11-16-2021
12:43 PM
I'm using proc import for a .txt file and the delimiter in it is |.
My DBMS line had been DBMS = TAB REPLACE; but that does not work with the | delimiter.
I've also tried
DBMS = DLM = '|' REPLACE;
DBMS = DLM REPLACE;
DBMS = '|' REPLACE;
None of them work. Anyone with any idea what would work? Any info is appreciated.
... View more
07-19-2021
03:13 PM
I don't know what icon you mean to right-click. If I right-click my SAS icon before opening SAS I don't see that. And after I open SAS I don't have any icon to right-click anymore.
... View more