- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I have many character variables that begin with "ACT_".
I need to change blanks (i.e. "") for these variables to "missing".
Any ideas how to do this?
Thank you.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
A better demo:
/*Creating sample data HAVE*/
data have;
array ACT_(20) $ ;
call streaminit(5);
do i = 1 to 20;
x = rand("Integer", 1, 20);
if mod(x,2)=0 then ACT_(i)='blah';
end;
drop x i;
run;
/*Your requirement to Impute word Missing to the blank values */
data want;
set have;
array t(*)$ ACT_:;
do i=1 to dim(t);
if missing(t(i)) then t(i)='Missing';
end;
drop i;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data want;
set have;
array t(*)$ ACT_:;
do i=1 to dim(t);
if missing(t(i)) then t(i)='Missing';
end;
drop i;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
A better demo:
/*Creating sample data HAVE*/
data have;
array ACT_(20) $ ;
call streaminit(5);
do i = 1 to 20;
x = rand("Integer", 1, 20);
if mod(x,2)=0 then ACT_(i)='blah';
end;
drop x i;
run;
/*Your requirement to Impute word Missing to the blank values */
data want;
set have;
array t(*)$ ACT_:;
do i=1 to dim(t);
if missing(t(i)) then t(i)='Missing';
end;
drop i;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you.
Is there also a way to increase the length of each of the variables that start with ACT_: ?
Their current length is 4.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I'm afraid No for the vars those of its descriptors have been already read at compile time before execution. So, in that case, you may need a new set of vars in defined in another array and drop the set with smaller length after the look up
@gzr2mz39 wrote:
Thank you.
Is there also a way to increase the length of each of the variables that start with ACT_: ?
Their current length is 4.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you, @novinosrin !
I want to use your example code for e scenario where my condition to replace the values with missing observations is different. Instead of replacing missing observations with 'missing' in a character variable,
I have a list of numeric variables with a prefix var_name_: and I want to replace the existing observations which are numbers with missing . (later I want to assign other values)
I tried the following code but I think my t(i) is not connected to my conditions to assign missing.
I appreciate it if you may help me with this. Thanks
data want;
set have;
array t(*) var_name_:;
do i=1 to dim(t);
if var_1 in (2,3) and var_2 in (1,3,4,5,6,7,10,13,14,16) then t(i)=.;
end;
drop i;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi @Emma_at_SAS Your condition isn't quite clear to me-
"I have a list of numeric variables with a prefix var_name_: and I want to replace the existing observations which are numbers with missing ."
1. Do you want to replace missing numeric variables with something?
2. Or do you want to replace some numbers with missing?-- This seems closer to your description. Your code seems okay. What do you see in LOG and output. What is not correct?
Alternatively, please post a sample of your INPUT and expected OUTPUT. I can give it a go. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you @novinosrin for investigating my question. Your second point would be my question. As @PaigeMiller mentioned a more clear version of my question would be this
I would like to be able to do it with a loop as well but I cannot yet.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
This was answered in your other thread at https://communities.sas.com/t5/SAS-Programming/How-to-set-the-observations-for-a-groups-of-variables...
Best practice is to not change the subject of this thread (where the desired result was 'missing', you are asking for something different), and keep your question in its own thread.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@gzr2mz39 wrote:
I have many character variables that begin with "ACT_".
I need to change blanks (i.e. "") for these variables to "missing".
Any ideas how to do this?
Thank you.
Do your current values actually have quote marks in them? If not then your value is already "missing".
Run this code and look in the log to see if the message is present:
data example; length var $ 10; var=''; if missing(var) then put "WARNING: Value of VAR is missing!"; run;