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-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!

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.

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
  • 3 replies
  • 7646 views
  • 3 likes
  • 4 in conversation