BookmarkSubscribeRSS Feed
SIMMII
Calcite | Level 5

Hi,

 

I tried running this code for a file named ps2_train which initially looks like this (table of dummy variables renamed):

 

ps2_question2.sc3.PNG

And it gave me this output data:

ps2_question2.sc4.PNG

But then I tried this code to convert the y variable (character variable) into a numeric:

 ps2_question2.PNG

But it gave me this output:

 

ps2_question2_sc2.PNG

My question is: how can I convert the y variable into a numeric one and have it incorporated into the original output that I showed (with all the variables x1, job, married, education,etc.)??

 

Thank you!

5 REPLIES 5
Kurt_Bremser
Super User

Post the log from your code by copy/pasting the log text into a window opened with this button:

Bildschirmfoto 2020-04-07 um 08.32.59.jpg

In the future, post your code text in a window opened with the "little running man" button right next to the one indicated. Do not post pictures.

Patrick
Opal | Level 21

Below screenshot is from the answer I gave you on your previous question for the same challenge.

Patrick_0-1701511629949.png

The first data step in this sample code is to create some HAVE data in order to provide some self-contained code that can run on its own. This because you haven't provided such sample HAVE data.

You need of course to use your real table work.ps2_train however it's called in reality. So do not execute the first data step and use in the set statement of the 2nd data step the name of your actual table.

 

SIMMII
Calcite | Level 5

Hey Patrick, may I ask what you mean by HAVE data? In the parts you highlighted, do I have to create a new dataset or keep the ps2_train file? I'm still very new to SAS.

 

Thank you

Tom
Super User Tom
Super User

@SIMMII wrote:

Hey Patrick, may I ask what you mean by HAVE data? In the parts you highlighted, do I have to create a new dataset or keep the ps2_train file? I'm still very new to SAS.

 

Thank you


First thing to do is get out of the habit of writing code like this:

 

data XYZ;
  set XYZ;
...

The name on the DATA statement is the dataset you are trying to CREATE.  The name on the SET statement is the dataset you are reading into the data step.  So you are replacing your existing dataset with new dataset.  If there is some mistake in the logic of the data step you have destroyed your original XYZ dataset.

 

Instead always make a NEW dataset.   

data step1;
  set have;
  ....
run;

data step2;
  set step1;
....
run;

You can clean up later if you want using PROC DELETE.  Or just let SAS remove all of the WORK datasets when you close your SAS session.

 

Also make sure to share TEXT (such as SAS Code, SAS Logs, or DATA).  I you post code and data as PICTURES instead of actual text then people trying to help cannot just copy the code and make fixes to it.

 

And make sure to use the insert Code or Insert SAS Code button on the forum editor to get a pop-up window to paste/type/edit the text or SAS code you want to share.  That way the forum software does not try to flow the text into paragraphs.  It also makes it stand out as different from the text of the actual question/posting.

SIMMII
Calcite | Level 5
I see, thank you very much! I'll use the insert code feature next time, sorry about that!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 1387 views
  • 0 likes
  • 4 in conversation