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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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