BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
rvsidhu035
Quartz | Level 8
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;
1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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

7 REPLIES 7
WarrenKuhfeld
Rhodochrosite | Level 12

Why not just run it and see for yourself?

art297
Opal | Level 21

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

 

rvsidhu035
Quartz | Level 8

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;
WarrenKuhfeld
Rhodochrosite | Level 12

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.

rvsidhu035
Quartz | Level 8
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

WarrenKuhfeld
Rhodochrosite | Level 12

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.

art297
Opal | Level 21

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

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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