Hello, in my statistics university-course we have a group assignment where we are supposed to do a regression analysis, a predictive model for wage.
We are given a dataset with 2670 ish observations with the variables Wage, Education, Experience etc, One of the variables is flexibility, the 'observation' (=person being interviewed) is coded as 0 for No and 1 for Yes, when asked the question:
"Do you have any type of flexible working hours, ie You can, within certain limits decide when you start and finish work? "
The problem I have is that I, after hours of me+my assignmentgroup-buddies googling it but finding no concrete answer (that we can understand), don't know how to code the data which is numerical, to character variables (dummy variables)
Does anyone know how to solve our problem?
Thanks in advance!
If you want the new variables to contain yes or no, use a defined format:
(create the format)
proc format library=work;
value yesno
0='N'
1='Y'
other='*'
;
run;
then do
newvar = put(oldvar,yesno.);
in a data step.
Dear KurtBremser,
How to write code for second step of your comment?
<then do
newvar = put(oldvar,yesno.);
in a data step.>
As I am new with sas and my data was import from Spss.
Thank you.
Well, take your pick:
proc format;
value yn
1 = "Yes"
0 = "No";
run;
data yourdata;
set yourdata;
format yourvariable yn.;
run;
I don't like formats however, so:
data yourdata;
set yourdata;
select(yourvariable);
when(1) decoded_variable="Yes";
when(0) decoded_variable="No";
otherwise decoded_variable=strip(put(yourvariable,best.));
end;
run;
You can also do an SQL case when, or merge the coded value in from a dataset, or create a sub-query with a code list table which is my preferred method. So have a dataset for coded values then:
proc sql;
create table WANT as
select A.*,
(select THIS.LONG_VALUE from DECODE_DATASET THIS where THIS.CODE=A.CODE) as LONG_VALUE
from HAVE A;
quit;
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.