DATA Step, Macro, Functions and more

what is the ouptput for this sas code?

Accepted Solution Solved
Reply
Contributor
Posts: 56
Accepted Solution

what is the ouptput for this sas code?

DATA CAPITALIZE;
INFORMAT FIRST LAST $30.;
INPUT FIRST $ LAST $;
    FIRST = LOWCASE(FIRST);
    LAST = LOWCASE(LAST);
SUBSTR(FIRST,1,1) = UPCASE(SUBSTR(FIRST,1,1));
SUBSTR(LAST,1,1) = UPCASE(SUBSTR(LAST,1,1));
DATALINES;
ronaldcODy
THomaSeDISON
alberteinstein
;
run;

Accepted Solutions
Solution
‎12-29-2017 12:07 PM
PROC Star
Posts: 8,091

Re: what is the ouptput for this sas code?

Posted in reply to rvsidhu035

Just follow the code you submitted in your most recent example.

DATA CAPITALIZE;
INFORMAT FIRST LAST $30.;
INPUT FIRST $ LAST $;
    FIRST = LOWCASE(FIRST);
    LAST = LOWCASE(LAST);
SUBSTR(FIRST,1,1) = UPCASE(SUBSTR(FIRST,1,1));
SUBSTR(LAST,1,1) = UPCASE(SUBSTR(LAST,1,1));
DATALINES;
ronaldcODy THomaSeDISON
;
run;

You're reading one record that has two strings:

first=ronaldcODy 
and
last=THomaSeDISON

You're then making all of the letters, of both, to be lower case. i.e.,

ronaldcody
and
thomasedison

You're then make the first letter, of each, to be uppercase:

Ronaldcody
and
Thomasedison

Art, CEO, AnalystFinder.com

 

View solution in original post


All Replies
SAS Super FREQ
Posts: 496

Re: what is the ouptput for this sas code?

Posted in reply to rvsidhu035

Why not just run it and see for yourself?

PROC Star
Posts: 8,091

Re: what is the ouptput for this sas code?

Posted in reply to rvsidhu035

I agree with @WarrenKuhfeld however, before running the code, suggest that you add a space between first and last names as shown in the example from Ron's book:

DATA CAPITALIZE;
INFORMAT FIRST LAST $30.;
INPUT FIRST $ LAST $;
    FIRST = LOWCASE(FIRST);
    LAST = LOWCASE(LAST);
SUBSTR(FIRST,1,1) = UPCASE(SUBSTR(FIRST,1,1));
SUBSTR(LAST,1,1) = UPCASE(SUBSTR(LAST,1,1));
DATALINES;
ronald cODy
THomaS eDISON
albert einstein
;
run;

Art, CEO, AnalystFinder.com

 

Contributor
Posts: 56

Re: what is the ouptput for this sas code?

my doubts here:

1.number of variables are four or two

2.i am get first,last,r,t

3.we get four variable and theri answer like this==first(ronaldcody),last(thomasedison),r=R,t=T

4.but i get only two variable FIRST=Ronaldcodv, LAST=Thomasedison

5.i want explain for this

DATA CAPITALIZE;
INFORMAT FIRST LAST $30.;
INPUT FIRST $ LAST $;
    FIRST = LOWCASE(FIRST);
    LAST = LOWCASE(LAST);
SUBSTR(FIRST,1,1) = UPCASE(SUBSTR(FIRST,1,1));
SUBSTR(LAST,1,1) = UPCASE(SUBSTR(LAST,1,1));
DATALINES;
ronaldcODy
THomaSeDISON
alberteinstein
;
run;
SAS Super FREQ
Posts: 496

Re: what is the ouptput for this sas code?

Posted in reply to rvsidhu035

This code does not create variable R and T.  You must be referring to some other program. SAS goes to a new line when it does not find Last on the same line as First.  This works fine in the first pass but not in the second pass where you get a lost card error.

Contributor
Posts: 56

Re: what is the ouptput for this sas code?

Posted in reply to WarrenKuhfeld
DATA CAPITALIZE;
INFORMAT FIRST LAST $30.;
INPUT FIRST $ LAST $;
    FIRST = LOWCASE(FIRST);
    LAST = LOWCASE(LAST);
SUBSTR(FIRST,1,1) = UPCASE(SUBSTR(FIRST,1,1));
SUBSTR(LAST,1,1) = UPCASE(SUBSTR(LAST,1,1));
DATALINES;
ronaldcODy THomaSeDISON
;
run;

I AM CONFUSE OUTPUT OF THIS PROGRAM

FIRST=Ronalddcody, LAST=Thomasedison

kindly explain

SAS Super FREQ
Posts: 496

Re: what is the ouptput for this sas code?

Posted in reply to rvsidhu035

As @art297 pointed out, you left out the blanks. SAS reads the first line as the first name then the second line as the last name.  The code capitalizes the first letter of each and lowercases the rest.  Then SAS tries again and ends since it cannot find a last name (as I mentioned before).  SAS continues to the next line when it can't find all the input on the current line.

Solution
‎12-29-2017 12:07 PM
PROC Star
Posts: 8,091

Re: what is the ouptput for this sas code?

Posted in reply to rvsidhu035

Just follow the code you submitted in your most recent example.

DATA CAPITALIZE;
INFORMAT FIRST LAST $30.;
INPUT FIRST $ LAST $;
    FIRST = LOWCASE(FIRST);
    LAST = LOWCASE(LAST);
SUBSTR(FIRST,1,1) = UPCASE(SUBSTR(FIRST,1,1));
SUBSTR(LAST,1,1) = UPCASE(SUBSTR(LAST,1,1));
DATALINES;
ronaldcODy THomaSeDISON
;
run;

You're reading one record that has two strings:

first=ronaldcODy 
and
last=THomaSeDISON

You're then making all of the letters, of both, to be lower case. i.e.,

ronaldcody
and
thomasedison

You're then make the first letter, of each, to be uppercase:

Ronaldcody
and
Thomasedison

Art, CEO, AnalystFinder.com

 

☑ This topic is solved.

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

Discussion stats
  • 7 replies
  • 200 views
  • 3 likes
  • 3 in conversation