我想要一个代码来将列中的数字替换为字符。
例如:0-“否”1-“是”。
我尝试使用 if/else 但它不起作用!
Data Assign2.Grocery_coup_two;
Set Assign2.Grocery_coupons;
If Heath_food_Store = 0
then Health_food_Store = "No";
Else Health_food_Store = "Yes";
Run;
Health_Food_Store
0
0
0
0
1
0
1
0
0
0
1
0
1
0
0
1
Run Code Online (Sandbox Code Playgroud)
您的解决方案不起作用,因为您正在尝试将数字变量转换为字符串变量。解决此问题的一种方法是将数字变量重命名为 _old,然后运行 if-else 语句:
Data Assign2.Grocery_coup_two;
Set Assign2.Grocery_coupons (rename = (Health_food_Store = Health_food_Store_old));
If Heath_food_Store_old = 0
then Health_food_Store = "No";
Else Health_food_Store = "Yes";
DROP Health_food_Store_old;
Run;
Run Code Online (Sandbox Code Playgroud)