I'm conducting an analysis on SAS 9.4 with health insurance enrollment data and want to understand the enrollment patterns before and after a diagnosis. I have monthly data for several years which I want to select 24 rolling months based around a diagnosis date. I want to copy over the select months into new columns based on the start month range. I have a dummy example below where month1-month7 are the enrollment months 1 through 7 and start_month is the number of the start month and end _month is the number of the end month of the range. I want to copy the data into the "next" variables for a range of 4. Adding "output" into the code doesn't solve the issue. The desired output at the end of this code. Thank you! *table creation for 2 examples; data try1; input month1-month7 start_month end_month; datalines; 1 2 3 4 5 6 7 2 4 1 2 3 4 5 6 7 4 7 ; run; proc print data=try1; run; *This straight copies the data into the "next" variables, not based on start/end range; data try2; set try1; array month month1-month7; /*enrollment months*/ array next next1-next4; /*want to copy over select months here*/ do i=1 to 4; /*interested in range of 4 months*/ next{i}=month{i}; /*this straight copies the data*/ end; run; proc print data=try2; run; *HERE IS WHERE I AM STUCK; *Trying to copy the select months based on the start and end range; *This code below only copies the last select month, which is wrong; data try3; set try1; array month month1-month7; /*enrollment months*/ array next next1-next4; /*want to copy over select months here*/ do k=start_month to end_month; /*start month and end month for each person*/ do i=1 to 4; /*interested in range of 4 months*/ next{i}=month{k}; /*this code is incorrect, it just copies the last month */ end; end; run; proc print data=try3; run; /*This is the desired output*/ data want; input month1-month7 start_month end_month next1-next4; datalines; 1 2 3 4 5 6 7 2 4 2 3 4 . 1 2 3 4 5 6 7 4 7 4 5 6 7 ; run; proc print data=want; run;
... View more
Please I need clarifcation on the code below. Thanks.
"data-type bis enclosed in parentheses and specifies one of the following: CHARACTER (or CHAR) | VARCHAR | INTEGER (or INT)."
proc sql; create table work.discount (Destination char(3), BeginDate num Format=date9., EndDate num format=date9., Discount num); quit;
I expect the data-type should be in parenthesis based on the syntax description above, e.g, Destination (char)(3). Please what am I missing?
... View more
Hello
With continue to previous post,
I want to create a new data set based on sashelp.class data set .
I want that in new data set will have 2 columns; Var_name ,Var_value.
I want it to be done only for numeric vars.
I want to identify the numeric vars automatically (Because I want to apply this code on different data sets)
proc sql;
create table numeric_Vars as
select libname, memname, name, type, length,
format, informat, label
from dictionary.columns
where libname = 'SASHELP' and memname = 'CLASS' and upcase(type) = 'NUM'
;
quit;
proc sql noprint;
select name into : Numeric_Vars_List SEPARATED by ' '
from numeric_Vars
;
quit;
%put &Numeric_Vars_List.; /**Age Height Weight**/
proc sql noprint;
select count(*) as nr_numeric_Vars into :nr_numeric_Vars
from numeric_Vars
;
quit;
%put &nr_numeric_Vars.;
data Long_Structure_Numeric_Vars_Data;
set sashelp.class;
array vv{&nr_numeric_Vars.} &Numeric_Vars_List.; /* _NUMERIC_ */
do j=1 to dim(vv);
Var_Name = vname(vv(i));
Var_Value = vv(i);
output;
end;
run;
The error in log is:
INFO: Character variables have defaulted to a length of 200 at the places given by: (Line):(Column). Truncation can result.
31:1 Var_Name
NOTE: Variable i is uninitialized.
ERROR: Array subscript out of range at line 31 column 19.
Name=Alfred Sex=M Age=14 Height=69 Weight=112.5 j=1 Var_Name= i=. Var_Value= _ERROR_=1 _N_=1
NOTE: The SAS System stopped processing this step because of errors.
NOTE: There were 1 observations read from the data set SASHELP.CLASS.
WARNING: The data set WORK.LONG_STRUCTURE_NUMERIC_VARS_DATA may be incomplete. When this step was stopped there were 0
observations and 9 variables.
... View more