BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
gzr2mz39
Quartz | Level 8

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.

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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;

View solution in original post

10 REPLIES 10
novinosrin
Tourmaline | Level 20
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;
novinosrin
Tourmaline | Level 20

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;
gzr2mz39
Quartz | Level 8

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.

 

novinosrin
Tourmaline | Level 20

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.

 


 

Emma_at_SAS
Lapis Lazuli | Level 10

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;

 

novinosrin
Tourmaline | Level 20

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!

Emma_at_SAS
Lapis Lazuli | Level 10

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

https://communities.sas.com/t5/SAS-Programming/How-to-set-the-observations-for-a-groups-of-variables...

I would like to be able to do it with a loop as well but I cannot yet.

Thanks!

PaigeMiller
Diamond | Level 26

@Emma_at_SAS 

 

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
Emma_at_SAS
Lapis Lazuli | Level 10
Thank you, Paige Miller! I first tried using this thread to answer my question. Then looking at my question with a different perspective I got my answer in that other thread. Thank you for your follow-up.
ballardw
Super User

@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;

 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 10 replies
  • 5379 views
  • 1 like
  • 5 in conversation