Hello, I am getting the following error messages when trying to merge two datasets. One of the datasets I am getting from a csv file, so maybe the issue could be there? I was trying to specify the length of the PID variable for the redcap_sort dataset from the redcap one, which is the one we got from the csv file. However, I keep getting messages that the variable has multiple lengths and it keeps truncating the data. Any PID after 999 gets shortened. So 1000 and 1001 become 100, 1010 becomes 101, etc. Any help or a nudge in the right direction would be greatly appreciated, thank you so much. Edit: The programming with the csv file already has: data work.redcap; %let _EFIERR_ = 0;
infile &csv_file delimiter = ',' MISSOVER DSD lrecl=32767 firstobs=1 ;
informat pid $500. ;
informat pid_ini $500. ; and the code for format: format pid $500. ; It has this for all the variables. I thought the above code would make it so that the variables would have that limit of 500 characters?
... View more
**ADDENDUM to original post: I realized that this issue was being caused by starting with a "RETAIN" statement, which I use to put the variables in the desired order. But I'd still like to leave this question up because I'd appreciate any feedback on: How does a RETAIN statement work? When does it affect the outputs of a command in a DATA step? Does anyone have alternate/preferred strategies for reordering the variables in a dataset? Thanks! *********************************************************************** Original post: Hello SAS community, I'm very confused about how SAS deciphers "IF" Statements in the DATA step. In this specific case, I'm working with an account dataset that has some conflicting information about when accounts close, and I am constructing an "effective" close date. Earlier in my data step, I used some IF statements to construct my desired close date. The last step is to convert that numeric close date to a string variable in the format YYYYMM. Here's what I tried: DATA WORK.dates_test;
SET WORK.raw_dates;
close_eff_n = acct_close_dte_n; IF closed = 1 AND acct_close_dte_n = . THEN DO; close_eff_n = maxdate_n; END;
*(omitting some additional logic used here for parsimony);
IF close_eff_n > 0 THEN DO;
close_dte_eff = put(close_eff_n,yymmn.);
END;
RUN; I had earlier written this last segment as: close_dte_eff = put(close_eff_n,yymmn.); but this populated the string variable close_dte_eff with a value of "." when close_eff_n was missing, which is why I'm now trying to implement this conditional logic. The problem is: where this condition fails, SAS populates the close_dte_eff field with whatever the last non-failed value was, which is completely incorrect. e.g. I have: close_eff_n 01MAR2023 01APR2023 . . 01JUL2021 I want: close_eff_n close_dte_eff 01MAR2023 202303 01APR2023 202304 . . 01JUL2021 202107 But instead I get: close_eff_n close_dte_eff 01MAR2023 202303 01APR2023 202304 . 202304 . 202304 01JUL2021 202107 When I tried to replicate this problem with a simplified dataset, i.e. just taking the final input variables and creating the desired output, I got the result I want, so I suspect it might have something to do with the preceding IF-statements. I can think of plenty of workarounds to get this to work as intended, so my question is not so much how to fix this, but why is this happening? There's something fundamental about how the "IF-statement" is being processed where rows that fail the "IF" condition are being populated with the value of the last row that met that condition, and I would like to understand when SAS applies this behavior and when it does not. I can see this being a useful feature in some limited cases, but it's generally not what I would want to do when applying conditional logic. I had thought that these sort of situations where SAS operates on one row depending on what was in the previous row only happen when there is a "BY" statement, but obviously that's incorrect as there is no "BY" statement in this DATA step. I'd really appreciate some explanation as to when actions are applied to rows that do not meet the specified condition in an "IF" statement, and how to control that behavior, so I can make sure that the commands I write are applying to the rows that I expect them to apply to. Please let me know if I can provide any other context or information that would be helpful. Many thanks, Scott
... View more
Hello SAS community! I have a dataset where each entry has a date and timestamp in "DATETIME20." format. Examples of data entry dates (there are tens of thousands in each month, going back many years): 16FEB2021:07:02:19 28MAR2023:11:52:22 06JAN2024:17:23.51 21APR2024:23:02:38 I am trying to run a proc freq where I get the count of the events by month and year. Ideally the output would look something like this: NOV23 37248 DEC23 41836 JAN24 39234 FEB24 52868 or even better NOV2023 37248 DEC2023 41836 JAN2024 39234 FEB2024 52868 My code is presently: PROC FREQ DATA=FLAGSDAT; TABLE ENTRY_DATE*FLAG_VALUE / NOPERCENT NOCUM NOROW NOCOL; RUN; The current code's output looks like this (using a dummy dataset for speed of testing where all the timestamps are at midnight): 31DEC2023:00:00:00 ‚ 9 01JAN2024:00:00:00 ‚ 11 22JAN2024:00:00:00 ‚ 13 13FEB024:00:00:00 ‚ 12 I tried using this code: PROC FREQ DATA=FLAGSDAT; TABLE ENTRY_DATE*FLAG_VALUE / NOPERCENT NOCUM NOROW NOCOL; FORMAT ENTRY_DATE MONYY.; RUN; But that did not work. Any advice for a simple fix to get the dates in the PROC FREQ output to just be MONYY or MONYYYY? For my dummy data, I would like the output to look like: DEC2023 9 JAN2024 24 FEB2024 12 Thank you in advance!
... View more
Please can someone help me. I have SAS 9 table with colonne TPS whixh specify the duration. Eg i can have in this variable modality like 30:22:00. After chargin this table in my CASLIB, for the same record this variable shows 6:22:00.
Seems like SAS ignore the 24 hours . After 24hours SAS set to null the duration.
How can i find issue to this problem ?
Thks
... View more
Hello,
I am running many SAS code in cascade and I have this error:
ERROR: You cannot open WORK.FICHIER_IBC_CORR.DATA for output access with member-level control because WORK.FICHIER_IBC_CORR.DATA is in use by you in resource environment IOM ROOT COMP ENV.
How to solve this issue.
Is it related to my SAS EG config.
... View more