BookmarkSubscribeRSS Feed
Schteeke
Calcite | Level 5

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!

3 REPLIES 3
Kurt_Bremser
Super User

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.

Kenndy
Calcite | Level 5

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.

 

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

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
  • 3010 views
  • 6 likes
  • 4 in conversation