Hi all,
Do I really have to put the dollar sign in every time to make this data a character value?
data learn.survey;
infile '/folders/myfolders/71442_example/survey.txt';
input Subject_Id Gender $ Age Salary Ques1 $ Ques2 $ Ques3 $ Ques4 $ Ques5 $;
label
subject_id = "Subject ID"
Age = "Age as of 1/1/2006"
Salary = "Yearly Salary"
Ques1 = "The governor doing a good job"
Ques2 = "The property tax should be lowered"
Ques3 = "Guns should be banned"
Ques5 = "The schools need to be expanded"
;
run;
Because this will not work
data learn.survey;
infile '/folders/myfolders/71442_example/survey.txt';
input Subject_Id Gender $ Age Salary Ques1-Ques5 $;
label
subject_id = "Subject ID"
Age = "Age as of 1/1/2006"
Salary = "Yearly Salary"
Ques1 = "The governor doing a good job"
Ques2 = "The property tax should be lowered"
Ques3 = "Guns should be banned"
Ques5 = "The schools need to be expanded"
;
run;
This should work better - the error is giving you a hint:
input Subject_Id Gender $ Age Salary (Ques1-Ques5) ($);
This should work
input Subject_Id Gender $ Age Salary (Ques1-Ques5) $;
I get this error when I try that, it's weird because the parentheses is clearly closed off
This should work better - the error is giving you a hint:
input Subject_Id Gender $ Age Salary (Ques1-Ques5) ($);
To apply a format (or in this case a modifier) to a list of variables you need to put both the variable list and the format list in parentheses.
(Ques1-Ques5) ($)
Note that you only need the $ informat modifier because you have not yet defined the variables. If you had already defined the variables then you wouldn't need to $ in the INPUT statement.
In a length statement the length specification applies to all of the variables listed before it.
data learn.survey;
infile '/folders/myfolders/71442_example/survey.txt';
length Subject_Id 8 Gender $8 Age Salary 8 Ques1-Ques5 $8;
input Subject_Id -- Ques5 ;
label
subject_id = "Subject ID"
Age = "Age as of 1/1/2006"
Salary = "Yearly Salary"
Ques1 = "The governor doing a good job"
Ques2 = "The property tax should be lowered"
Ques3 = "Guns should be banned"
Ques5 = "The schools need to be expanded"
;
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.