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?
Please see
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.
So, just to be clear, what does your desired result look like?
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.
Please see
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.
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.
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.
Ready to level-up your skills? Choose your own adventure.