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
Super User

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

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

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