BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
skatethejake
Fluorite | Level 6

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;
1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

This should work better - the error is giving you a hint:

input Subject_Id Gender $ Age Salary (Ques1-Ques5) ($);

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

This should work

 

input Subject_Id Gender $ Age Salary (Ques1-Ques5) $;
 
--
Paige Miller
skatethejake
Fluorite | Level 6

Screen Shot 2020-08-15 at 7.08.46 PM.png

 I get this error when I try that, it's weird because the parentheses is clearly closed off

SASKiwi
PROC Star

This should work better - the error is giving you a hint:

input Subject_Id Gender $ Age Salary (Ques1-Ques5) ($);
Tom
Super User Tom
Super User

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;

 

 

SAS Innovate 2025: Register Now

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!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1028 views
  • 3 likes
  • 4 in conversation