- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Proc freq data=have;
Var listofallchar;
Run;
data want;
set have;
if chav1="?" then chav1="15.0";
if chav2="?" then chav2="1.0";
... (25 char variables to type with 25 mode values)
this is the original code but I am tried to type all these char variables with their values. Any advice to use macro or a library? Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@Bal23 wrote:
this is the original code but I am tried to type all these char variables with their values. Any advice to use macro or a library? Thank you
Try an array instead.
https://stats.idre.ucla.edu/sas/seminars/sas-arrays/
If you have trouble, post your code, log and detailed explanation of the issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Proc contents data=have;
Run;
proc means data=have n missing;
var _numeric_;
run;
*there is no missing value for all numerical variables;
proc freq data=have;
tables listofallcharvariables;
run;
*by copy and paste the result to an excel file, sort it by the frequency of the value, descending (that is how I get each value that most people have for each variable; actually I notice all variables could be considered as numerical, the only thing is, it has “?” when the data is missing, so when there is “?”, this variable is considered as “char”. Could we convert all character variables to numerical variables and replace “?” to “.”)
data want;
set have;
if chav1="?" then chav1="15.0"; /*15.0 is the value that most people have for this variable, same rule applies below/
if chav2="?" then chav2="1.0";
... (25 char variables to type with 25 mode values) /*when i tried to type these 25 variables, it takes so much time, that is why I am seeking help*/
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Look at PROC STDIZE or STANDARDIZE (can't recall which) which have replacement for missing values options. Not sure Mode is an option but most other common metrics are such as median/mean or other similar measures.
Nothing from your response below negates my suggestion of using a loop to test each value and replace it.
@Bal23 wrote:
Proc contents data=have;
Run;
proc means data=have n missing;
var _numeric_;
run;
*there is no missing value for all numerical variables;
proc freq data=have;
tables listofallcharvariables;
run;
*by copy and paste the result to an excel file, sort it by the frequency of the value, descending (that is how I get each value that most people have for each variable; actually I notice all variables could be considered as numerical, the only thing is, it has “?” when the data is missing, so when there is “?”, this variable is considered as “char”. Could we convert all character variables to numerical variables and replace “?” to “.”)
data want;
set have;
if chav1="?" then chav1="15.0"; /*15.0 is the value that most people have for this variable, same rule applies below/
if chav2="?" then chav2="1.0";
... (25 char variables to type with 25 mode values) /*when i tried to type these 25 variables, it takes so much time, that is why I am seeking help*/
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I think , following might reach your need
data want;
set have;
array chr [*] $ _character_;
do i = 1 to dim(chr);
if cmiss(of chr[*]) then /*write your condition here*/;
output;end;output;
run;
Note: I haven't tested this code; so, am not sure about its performance.
Since am not very clear about your data, so why I haven't mentioned condition after "then"; If mode values were provided already then create macro for each value and give those macros as the reference after "then ".
MODE is a stat which you can be generated for a numeric variable.
Thank you & Regards,
Manoj.