Hey,
I ran into this message when trying to run a proc means:
/* Example 1: The simplest case character to numeric */ /* The resulting data set has both the original character variable and a new */ /* numeric variable. If you want the result to have just one variable with */ /* the original name, uncomment the DROP and RENAME statements. */ data new1; orig_var = '80000'; new_var = input(orig_var,8.); /* drop orig_var; */ /* rename new_var = orig_var; */ run; proc print; run;But am having trouble implementing it into my own program.
You weren't supposed to re-create the file paper.ceo_firm. Since you did, you'll have to re-create it!
What you wanted to run was:
data paper.ceo_firm; set paper.ceo_firm (rename=(BONUS=_BONUS STOCK_AWARDS=_STOCK_AWARDS)); BONUS=input(_BONUS,?? 8.); STOCK_AWARDS=input(_STOCK_AWARDS,?? 8.); run;
However, since you over-wrote the original file, you'll have to back up and recreate it before running the above code.
Art, CEO, AnalystFinder.com
No, you don't have to create a new file but, at the same time, you can't just make a character variable to be numeric.
However, you can rename the two fields, and then create the two numeric fields with the original names. e.g.:
data have; input x y (BONUS STOCK_AWARDS) ($); cards; 1 1 20 30 2 2 40 70 3 3 ? 12 4 4 U/K . ; data have; set have (rename=(BONUS=_BONUS STOCK_AWARDS=_STOCK_AWARDS)); BONUS=input(_BONUS,?? 8.); STOCK_AWARDS=input(_STOCK_AWARDS,?? 8.); run;
I added the double question marks to the input function so that your log wouldn't show a bunch of errors that you'll likely get due to non numeric values that can't be read as numbers.
Art, CEO, AnalystFinder.com
Here is your code as it appears in my program:
data paper.ceo_firm; input x y (BONUS STOCK_AWARDS) ($); cards; 1 1 20 30 2 2 40 70 3 3 ? 12 4 4 U/K . ; data paper.ceo_firm; set paper.ceo_firm (rename=(BONUS=_BONUS STOCK_AWARDS=_STOCK_AWARDS)); BONUS=input(_BONUS,?? 8.); STOCK_AWARDS=input(_STOCK_AWARDS,?? 8.); run; title "Table 1."; title2 "Summary Statistics"; title3 "CEO Compensation"; PROC MEANS data=paper.ceo_firm n mean median std min max skew maxdec=2; var salary bonus stock_awards; run;
I am not sure what this output is telling me though:
x y bonus stock_awards bonus stock_awards
1 | 1 | 1 | 20 | 30 | 20 | 30 |
2 | 2 | 2 | 40 | 70 | 40 | 70 |
3 | 3 | 3 | ? | 12 | . | 12 |
You missed the underscores in two of the variables in your output.
The code I suggested RENAMED the two character variables to have the same name but each preceded by an UNDERSCORE.
i.e. _BONUS is the original character variable while BONUS is now a numeric variable. The same is true for the other variable.
You'd want to use the two new variables (i.e. BONUS and STOCK_AWARDS .. the ones whose variable names DON'T begin with an UNDERSCORE) in your analysis.
Art, CEO, AnalystFinder.com
Actually, I'm confused by what you showed as your output. You said you ran:
PROC MEANS data=paper.ceo_firm n mean median std min max skew maxdec=2; var salary bonus stock_awards; run;
But then showed something with x, y and two sets of bonus and stock_awards. I don't know where that came from. It looks like the result of a PROC PRINT of the example I showed.
Art, CEO, AnalystFinder.com
I am confused as well--that is the output in paper.ceo_firm after I ran the code I posted a message ago.
Post your log! That is the best way for anyone to see what you ran.
Art, CEO, AnalystFinder.com
Here you are!
WEIGHT=
You weren't supposed to re-create the file paper.ceo_firm. Since you did, you'll have to re-create it!
What you wanted to run was:
data paper.ceo_firm; set paper.ceo_firm (rename=(BONUS=_BONUS STOCK_AWARDS=_STOCK_AWARDS)); BONUS=input(_BONUS,?? 8.); STOCK_AWARDS=input(_STOCK_AWARDS,?? 8.); run;
However, since you over-wrote the original file, you'll have to back up and recreate it before running the above code.
Art, CEO, AnalystFinder.com
How do I know this won't overwrite it again?
data paper.ceo_firm; set paper.ceo_firm (rename=(BONUS=_BONUS STOCK_AWARDS=_STOCK_AWARDS)); BONUS=input(_BONUS,?? 8.); STOCK_AWARDS=input(_STOCK_AWARDS,?? 8.); run;
Isn't this how I had it as well?
Because that isn't what you did. What you had run was:
data paper.ceo_firm; input x y (BONUS STOCK_AWARDS) ($); cards; etc.
That overwrote your original dataset.
SAS will simply do what you tell it to do (as long as there aren't errors in the code).
Art, CEO, AnalystFinder.com
When you say "recreate it", what do you mean? I simply deleted the code and re-ran the program, and everything looks the same as it was. Should it not be? Do I need to open a clean program and re-import the csv?
If you ran the code you posted a couple of posts back, then you'd have to go back to whatever step you ran to create the paper.ceo_firm dataset.
Art, CEO, AnalystFinder.com
Okay, well I just deleted some of the earlier code we had and then ran the one I just accepted as the solution. It worked in converting the variables.
Thanks!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.