Hi all,
I have a listing comprises of Numeric and Character, currently SAS recognized listing as character.
How to produce as numeric.
Var
1
2
2A
2B
3
IF VTYPE(VAR)=’N’ THEN VAR1 = input(VAR,2.);
ELSE VAR1 = PUT(VAR,2.);
What's wrong with the code?
A variable can only be one type: numeric or character. This holds through every observation in the data set - otherwise how could you reliably code something like sumvar=var1+var2;?
It is most definitely NOT the same as a spreadsheet, where each cell can be of a different type than other cells in the same column (which is the analog of a variable). That is an attribute of spreadsheets that has to be abandoned in SAS (or STATA or SPSS or other statistical packages).
If i would like to treat numeric as numeric, whereas character remains as character, can it be done?
@User_Help wrote:
If i would like to treat numeric as numeric, whereas character remains as character, can it be done?
With two variables. Create a numeric variable for the values you want to treat as numeric.
If you do not need to do calculations, add, subtract, multiply and so on, with a variable then it should not be numeric at all.
You want this ?
data have;
input Var $;
cards;
1
2
2A
2B
3
;
data want;
set have;
var_num=input(var,?? best.);
if missing(var_num) then var_char=var;
run;
Hi,
"Var" the list is in Text format.
Can i get the "Expected Result" as screenshot below?
1,2,3 is in General format, 2A, 2B is Character format. Result shown in single column.
@User_Help - Text Format and General Format are Excel concepts and have no meaning in SAS. From what I can see Column A and Column D are identical and all you are doing is changing the Excel format. You don't need SAS to do that. It's a lot easier just using Excel to format columns A and D.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.