Hi,
I tried running this code for a file named ps2_train which initially looks like this (table of dummy variables renamed):
And it gave me this output data:
But then I tried this code to convert the y variable (character variable) into a numeric:
But it gave me this output:
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!
Post the log from your code by copy/pasting the log text into a window opened with this button:
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.
Below screenshot is from the answer I gave you on your previous question for the same challenge.
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.
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
@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.
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.
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.