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

Hello every one 

I m cleaning my data but i confronted an issue which is 

i have variable data it is like multi response data (means there are more than one value for some observations)

for example 

obs   variable 

1        1,3,4

2        2,8,9

.

 .

Here, i need to change the value of the data from such type into 1 or 0

through fro example: if the obs contains 3 so change it 1 

 

what the code or proc to do this task?

of course i m using this way 

   data ceo1;
   set ceo1;
   array change _character_;
           do over change;
            if change=.  then change=0;
            end;
   run ;

is it correct?

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

 Please see

https://communities.sas.com/t5/New-SAS-User/Creating-dummy-variables-from-variables-with-multiple-va...

 

for two examples.

 

These assign values of 1 or 0 to array elements where you create an array with one variable for each possible value that occurs.

Note that these both assume that your values are sequential such as 1,2,3, …,8,9,10 or whatever . Additional logic is needed if you have gaps or non-sequential values.

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

So, just to be clear, what does your desired result look like?

Kurt_Bremser
Super User

Please do ALWAYS supply example data in a readily usable form that leaves NO ambiguities about variable types/lengths/formats and the content.

Otherwise we'll only be guessing.

The method to supply such data is a DATA STEP WITH DATALINES. See this example:

data have;
length variable $10;
input variable;
datalines;
1,3,4
2,8,9
;
run;

Then, post the expected outcome from this example data. This can be done in a simple tabular way, without SAS code.

 

Your code does not make sense. You define an array for all character variables, but then you test and set numeric values.

ballardw
Super User

 Please see

https://communities.sas.com/t5/New-SAS-User/Creating-dummy-variables-from-variables-with-multiple-va...

 

for two examples.

 

These assign values of 1 or 0 to array elements where you create an array with one variable for each possible value that occurs.

Note that these both assume that your values are sequential such as 1,2,3, …,8,9,10 or whatever . Additional logic is needed if you have gaps or non-sequential values.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 8114 views
  • 3 likes
  • 4 in conversation