DATA Step, Macro, Functions and more

character variable

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 17
Accepted Solution

character variable

The following SAS program is submitted:

 

data work.staff; 

JobCategory = ‘FA’;

JobLevel = ‘1’; 

Jobcategory = Jobcategory || JobLevel; run;

 

Which one of the following is the value of the variable JOBCATEGORY in the output data set?

 

  1. FA
  2. FA1
  3. FA 1
  4. ‘‘(missing character value)

 

Answer: A

 

 

 

how is it option A?


Accepted Solutions
Solution
‎02-02-2018 08:24 PM
PROC Star
Posts: 8,114

Re: character variable

Posted in reply to VISHNU239

Because the length of JobCategory is set as 2.

 

Now, just as interesting, try to figure out the results of:

data work.staff; 
  JobCategory = 'FA';
  JobLevel = '1'; 
  Jobcategory2 = Jobcategory || JobLevel;
  Jobcategory = Jobcategory || JobLevel;
  output;
  JobCategory = 'FAA';
  JobLevel = '2'; 
  Jobcategory2 = Jobcategory || JobLevel;
  Jobcategory = Jobcategory || JobLevel;
  output;
run;

Art, CEO, AnalystFinder.com

 

View solution in original post


All Replies
Solution
‎02-02-2018 08:24 PM
PROC Star
Posts: 8,114

Re: character variable

Posted in reply to VISHNU239

Because the length of JobCategory is set as 2.

 

Now, just as interesting, try to figure out the results of:

data work.staff; 
  JobCategory = 'FA';
  JobLevel = '1'; 
  Jobcategory2 = Jobcategory || JobLevel;
  Jobcategory = Jobcategory || JobLevel;
  output;
  JobCategory = 'FAA';
  JobLevel = '2'; 
  Jobcategory2 = Jobcategory || JobLevel;
  Jobcategory = Jobcategory || JobLevel;
  output;
run;

Art, CEO, AnalystFinder.com

 

Occasional Contributor
Posts: 17

Re: character variable

yeah got it sir. examples helped me in understanding. what does the symbol || mean and what is its function?
PROC Star
Posts: 8,114

Re: character variable

Posted in reply to VISHNU239

|| is similar to the catt function, i.e., it combines strings without trimming spaces from the right or removing any leading spaces.

 

Art, CEO, AnalystFinder.com

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 162 views
  • 0 likes
  • 2 in conversation