01-27-2025
emaguin
Quartz | Level 8
Member since
05-06-2019
- 81 Posts
- 15 Likes Given
- 1 Solutions
- 5 Likes Received
-
Latest posts by emaguin
Subject Views Posted 184 01-28-2025 12:29 PM 1002 01-28-2025 11:41 AM 1038 01-28-2025 09:39 AM 1204 01-27-2025 04:05 PM 730 12-18-2024 05:37 PM 1162 08-24-2023 12:41 PM 1169 08-24-2023 12:20 PM 1169 08-24-2023 12:17 PM 1197 08-24-2023 11:16 AM 864 03-02-2023 09:15 AM -
Activity Feed for emaguin
- Posted Re: substract a date variable from a datetime variable with difference being in years and decimals on SAS Programming. 01-28-2025 12:29 PM
- Posted Re: substract a date variable from a datetime variable with difference being in years and decimals on SAS Programming. 01-28-2025 11:41 AM
- Posted Re: substract a date variable from a datetime variable with difference being in years and decimals on SAS Programming. 01-28-2025 09:39 AM
- Posted substract a date variable from a datetime variable with difference being in years and decimals on SAS Programming. 01-27-2025 04:05 PM
- Posted reference all variables in data set in vector on SAS Programming. 12-18-2024 05:37 PM
- Posted Re: A) read correlation matrix into sas; B) use that matrix as input to proc corr to compute reliabi on Statistical Procedures. 08-24-2023 12:41 PM
- Posted Re: A) read correlation matrix into sas; B) use that matrix as input to proc corr to compute reliabi on Statistical Procedures. 08-24-2023 12:20 PM
- Posted Re: A) read correlation matrix into sas; B) use that matrix as input to proc corr to compute reliabi on Statistical Procedures. 08-24-2023 12:17 PM
- Posted A) read correlation matrix into sas; B) use that matrix as input to proc corr to compute reliability on Statistical Procedures. 08-24-2023 11:16 AM
- Posted Generating data on SAS Programming. 03-02-2023 09:15 AM
- Posted proc mixed influence analysis output on Statistical Procedures. 11-21-2022 05:32 PM
- Posted Re: multilevel beta regression errors on Statistical Procedures. 10-26-2022 12:42 PM
- Posted Re: multilevel beta regression errors on Statistical Procedures. 10-21-2022 09:46 AM
- Posted Re: multilevel beta regression errors on Statistical Procedures. 10-21-2022 09:16 AM
- Posted Re: multilevel beta regression errors on Statistical Procedures. 10-19-2022 03:11 PM
- Posted multilevel beta regression errors on Statistical Procedures. 10-17-2022 04:09 PM
- Posted Re: Q1: retain statement; Q2: finding my previous questions and their replies on SAS Programming. 08-31-2022 02:53 PM
- Posted Re: Q1: retain statement; Q2: finding my previous questions and their replies on SAS Programming. 08-31-2022 11:04 AM
- Posted Q1: retain statement; Q2: finding my previous questions and their replies on SAS Programming. 08-31-2022 10:45 AM
- Posted proc transpose on SAS Programming. 06-27-2022 04:12 PM
-
Posts I Liked
Subject Likes Author Latest Post 1 1 2 2 3 -
My Liked Posts
Subject Likes Posted 1 01-06-2021 04:32 PM 1 09-30-2020 05:35 PM 1 08-25-2020 02:30 PM 2 08-02-2019 09:45 AM
01-28-2025
12:29 PM
"The most likely cause for getting age of 53 is that you messed up the order of the arguments and which one had DATE values versus DATETIME values so that you ended up calculating the number of years since 1960." YES. That is exactly what I did. Case closed. Thank you for your help and persistence and to all who replied, thank you. Gene Maguin
... View more
12-18-2024
06:38 PM
1 Like
@ballardw wrote:
...
The Array statement also requires ( ) not { }. The brackets and braces in a data step are reserved for already defined arrays and character values, something appearing inside quote marks.
...
That statement is false.
You can use any of (), {} or [] when setting the dimensions of an array.
array md (*) _numeric_;
array md [*] _numeric_;
array md {*} _numeric_;
In fact the array statement in a DATA step does not need to have anything at all at that point when you have provided it a list of variable names, like in this case.
array md _numeric_;
But there are some newer places where SAS allows the use of an ARRAY statement such as PROCs that included code blocks and PROC FCMP. And some of those do required the dimension setting to be included, even when they allow the use * instead of an actual dimension.
... View more
08-25-2023
07:34 AM
1 Like
https://support.sas.com/kb/30/333.html#errinvar
proc corr data=sashelp.class alpha;
var weight height age;
run;
... View more
03-02-2023
09:36 AM
data want;
do record_number=1 to 20000;
x1=rand('normal',3,2);
...
output;
end;
run;
I leave the code to calculate X2 and Y to you as a homework assignment. Please see the RAND() function documentation for other random number generation options.
... View more
11-21-2022
05:32 PM
This may not the right forum. Anyway, i running some very simple proc mixed (multilevel) models and specifying influence statistics. for example: ods graphics on; title 'var on age rise*age No outliers'; proc mixed data=no_outs; model var_rise=rise_rev agecenX rise_rev*agecenX/ solution influence residual outp=var_ageint_no; random Intercept/type=vc subject=evq_id; run; ods graphics off; Runs fine, no errors. Now the problem. I've learned that i can save the output (results) and show it to others later; it's just html; opens in any browser. So i do the same thing here and look at the saved output. I'm stunned: all the plots are GONE and replaced by little colored squares in the upper left. I want to show that output and it's going to be looked at on a computer that does not have sas installed. AND even if sas were on that computer and i open an output file through sas those plots are still gone! Let's say i don't know enough to know what to do. What do i do? Thanks.
... View more
11-03-2022
12:18 PM
Sorry, please, ignore my last post. The last example works perfectly.
... View more
10-26-2022
12:42 PM
Steve, Thank you. I would never have found that. I'll try it out but it certainly looks like it is what I need. One thing I noticed that that clicking on the complete code link is a dead end. Searching on "sas glimmix" and clicking on first result (https://support.sas.com/rnd/app/stat/procedures/glimmix.html) gets to a page with "SAS/STAT Software" as the heading. Under the examples is the example you pointed me to but there it is listed as Example 49.4 (and the link to the complete code works). So, who knows why; it like going into your familiar grocery store and nearly everything has been rearranged. Again, thank you.
... View more
08-31-2022
05:16 PM
I submit that one-to-one messages are the wrong tool for providing answers to SAS problems. The discussion about SAS problems (like this thread) should be public so that everyone can learn and everyone can benefit; and so multiple solutions can be provided.
... View more
06-03-2022
02:51 PM
BEST, $, DATE etc formats are part of the BASE SAS installation. So you do not need to define them to use them.
First thing to try is to tell SAS that it is not an ERROR if the format cannot be found, then you can at least look at the data.
options nofmterr;
Do you have the formats saved somewhere? Perhaps you just need to tell SAS where to find them. Modify the FMTSEARCH option. Either directly set it or use the APPEND= or INSERT= option to add a new catalog to the current list of catalogs to search.
The most likely source of those formats was the conversion of the SPSS file into a SAS dataset. The SPSS file probably had "data labels" and those were translated into user defined formats and the formats were attached to the variables. When you later combined the data from SPSS with the data from the CSV file you did not bother to remove the format from the variables. You probably do not need all of those formats. If the variables MS_CLI... use the same set of codes then you can probably use one format to decode all of them. Or perhaps the coded values are meaningful enough that you do not need to see the decoded values to work with the data.
Most likely if you re-convert the SPSS file into a SAS dataset you will get the formats defined again. This time either change the options used so that the formats are written to a permanent catalog instead of a WORK catalog or copy the formats from the WORK.FORMATS catalog into a permanent catalog that you can use in the future.
Note there is normally no reason to attach formats or informats to variables read from a CSV file. You do not need them with normal numbers or strings, so not need for the BEST or $ formats to be attached. (NOTE A lot of novice coders think that attaching a FORMAT or an INFORMAT to a variable somehow is defining the variable. Those statements will only define the variable as side effect when the variable was not previously defined. Use the LENGTH statement to DEFINE the variables).
Attach formats to variables whose values you want to display in a special way. Like DATE, TIME or DATETIME values that just look like random numbers to humans if not formatted.
Similarly for reading the text in the CSV into values you do not usually need to specify any informat. (Again DATE, TIME and DATETIME values are normally the exception). And even if you did need to use an informat when reading the value you could include it in the INPUT statement instead of permanently attaching it to the variable.
... View more
06-03-2022
11:50 AM
SAS has two data types. Floating point numbers and fixed length character strings. The best way to define whether your variable is numeric or character (and if character how many bytes it can hold) is with the LENGTH statement. Floating point numbers are 8 bytes long so in general it is best to use a length of 8 for them (shorter length means less precision). Use of a $ in front of the length will indicate a character variable. Maximum length of a character variable is 32,767 bytes. If you don't define your variables (or read them from an input dataset) before using them in other statements, such as assignment statements or INPUT or FORMAT or INFORMAT statements, then SAS will make its best guess how to define the variable.
SAS uses FORMATS for displaying values as text and INFORMATS for converting text into values. Numeric formats display numeric values as text. Character formats display character values as text. Numeric informats convert text into numeric values. Character informats convert text into character values.
The normal numeric format, usually shown in the documentation as w.d, will display numbers with a fixed total number of characters (the w or width) and a fixed number of character after the decimal place (the d). If the decimal positions are zero or not specified then the decimal point is not added. The decimal point counts in the total width. You can also call this format by its alias F. So F10.4 would mean 5 characters for digits (or negative sign), one character for the decimal point and four characters for digits after the decimal point.
BEST is the name of a FORMAT that will attempt to find the "best" way to display a number within the width limit specified. So it will adjust the number of decimal places included based on the value. It will even switch to scientific notation if the the value cannot be fit otherwise.
For Character variables the names of the formats and informats start with a $.
Users can create their own custom formats (and informats) using PROC FORMAT. The formats are independent from the variables you might want to use them with. So unlike the SPSS "value label" feature if you have multiple variables that are using the same coded values you only need to define one format and then use it with as many variables are you want. So if you have a lot of variables coded as 1=Yes and 2=No then define a YESNO format and attach to all of them.
proc format;
values yesno 1='Yes' 2='No';
run;
data want;
set have;
format q1-q20 yesno. ;
run;
You can also decide to use a different format for the same variable at different times. For example the YYMM format will display date values using only the year and month numbers. So you could generated a summary of data by MONTH by just changing the way the date is displayed (as long as the procedure you are using actually groups by the display values instead of the actual values).
title1 'Summary by YEAR';
proc means data=have;
class date;
format date year4. ;
var income expense ;
run;
title1 'Summary by YEAR and MONTH';
proc means data=have;
class date;
format date yymm7. ;
var income expense ;
run;
... View more
11-01-2021
01:47 PM
When you MERGE the observations with the same values of the BY variables are combined. (If one or more of the datasets have multiple observations for the same set of BY variable values then the observations are matched in order and any dataset that runs out of observations for that group will just keep the values the last observation in the group had).
So in your example:
NOTE: There were 9145 observations read from the data set WORK.STACKY3.
NOTE: There were 36 observations read from the data set WORK.COHORTS2.
NOTE: The data set WORK.STACK4 has 9163 observations and 753 variables.
If none of the YBW values matched then the number of observations written would be the sum of the number read from each input. Since 9,163 is less than 9,145 plus 36 there are some value of YBW that did match. Since 9,163 is more than 9,145 there are some observations where the value of YBM did not match (or where that value appeared more than once in WORK.COHORTS2)
To find out exactly which they are you can use the IN= dataset options on the input datasets to create temporary variables that will be true when that dataset is contributing data.
... View more
09-15-2021
04:54 PM
SAS has many different flavors of DO statements.
Looks like you intended to run a the bare DO statement.
if x then do;
statement1;
statement2;
end;
But because of the missing semi-colon after the DO instead you ran a version of aniteration DO statement, which can have many forms:
do i=1 to 10;
do i=1,3,4,5;
do i=1,5 to 10,13 ;
But instead of multiple values you only had one value.
if (valcwk{i} ge 1 and valhwk{i} ge 1) then do vbacwk{i}=((valcwk{i}/2)*(9.0/A2WEIGHT))-(0.02*valhwk{i});
In your code the iteration variable is a reference to an array, vbacwk{i}, and SAS syntax does not allow that.
Here is clearer example that demonstrates the coding error:
81 data _null_;
82 set sashelp.class;
83 array n _numeric_;
84 do n[1]= 5-6 ;
-
73
76
ERROR 73-322: Expecting an =.
ERROR 76-322: Syntax error, statement will be ignored.
85 put n[1]=;
86 end;
87 run;
... View more
07-08-2021
04:03 PM
@emaguin wrote: I could have said array vlec16{5} A3LEC15_1 A3LEC15_3 A3LEC15_4 A3LEC15_6 A3LEC15_7; but why?? It's simpler to do what I did and then not use two of the variables and then delete them. So what! Like I said, understand the warning. But why did sas not execute the statement? It was a warning not an error. Gene Maguin
Because you did not "drop" A3Lec15_2 (or A3Lec16_2) you said the problem was with Lec16_2. You are now using different variable names than shown in your previous code snippet (A3Lec15). Which is one reason I asked for the entire data step, to see what you may be creating during the data step, exactly what you are "dropping". I strongly suspect you didn't create the variables that you claimed to attempt to drop.
A couple of other ways to parse comma delimited string of values and get a 1 or 1/0 coded variable.
data example;
infile datalines truncover;
input string $15.;
array v(7);
do i=1 to countw(string,',');
v[input(scan(string,i,','),f8.)]=1;
end;
datalines;
1
1,3
3,4,7
1,3,7
1,3,4,6,7
;
/* or to do 1/0 coding*/
data example;
infile datalines truncover;
input string $15.;
array v(7);
do i=1 to 7;
v[i]= index(string,put(i,f1.))>0;
end;
datalines;
1
1,3
3,4,7
1,3,7
1,3,4,6,7
;
Scan can pull a specific position number of a value from a delimited string. The last parameter is a list of delimiters. Lots simpler than trying to use the length and an offset. Probably not needed but sometimes you want to break up a string at different points and though it appropriate to include a specific delimiter in this example. The Index function returns a position in a string of a substring. SAS returns 1 for true or 0 for false with comparing the returned value from Index to > 0.
Index would not be appropriate for finding 1 if you might have values like 10, 11 or 101 though INDEXW or FINDW might.
I prefer 1/0 coded values for "any that apply" type questions because then a sum=total number of selections, mean=percentage of respondents that selected the choice.
BTW, 190 lines isn't particularly long for a data step.
... View more
07-07-2021
10:44 AM
I copied your code, stripped the line numbers and errors, and pasted into SAS Enterprise Guide. Then I used the Format Code feature to see the if/then and do/end matchups. I noticed this:
You don't use the do..end wrapper for these, but you do have an extra semicolon at each line and that might be an issue. When in doubt (even with just one code instruction after the then, put it in a do/end. Then if you have to add an additional statement later you're already covered.
... View more
05-19-2021
08:44 PM
1 Like
1. There is no need to use INTNX to create a datetime out of the dstarttim, it's already a DATETIME because that's how SAS stores datetimes. Read the reference from the prior link for more details. Apply a format to the variable to have it display correctly.
format dstarttim datetime22.;
2. Specify a data constant in the format of "DDMONYYYY"d - no 9. Since your variable is a datetime and you're comparing it to a date, you need to use DATEPART to get just the date portion as well.
if (datepart(dtstarttim) lt '15mar2020'd) then precovid=1;
3. If you want a seconds comparison, both need to have a time component.
if (dstarttim lt dhms('15mar2020'd, 0, 0, 0) ) then precovid=1;
@emaguin wrote:
I need to compute a date-time variable given the number of seconds (dstarttim, below) from 01.01.1960 (I think, but let's say it's true) and then do a comparison of that date with another date. Fortunately Cody has a chapter on date arithmetic in his book but unfortunately it doesn't include time. But from it i got the intnx function.
I wrote
ivuedone=intx('second','01jan60:00:00:00'dt,dstarttim,'same');
put ivuedone datetime18;
I get errors: iwuedone in line 1 is marked as an error and line 2 likewise not liked. I'm doing something wrong; what is it?
That's part A, now part B. I want to say
if (iwuedone lt '15mar2020' d9) then precovid=1;
Will that work?
Alternatively, how would this be written:
If (dstarttime le 15mar2020 in seconds) then precovid=1;
Thanks,
Gene Maguin
... View more