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

How do I print a variable containing capital letter X?

I have no idea how to write the code, please help. 

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

Assuming respop72015 represents the population in 2015, then here is one way to do it:

data have;
  infile '/folders/myfolders/USPOP.csv' dlm=',' dsd lrecl=200 firstobs=2;
  informat GEO_id $12.;
  informat GEO_display_label $40.;
  input GEO_id GEO_display_label respop72010-respop72015;
run;

proc print data=have (where=(index(GEO_display_label,'C') and
                      GEO_id ne '0400000US11'));
  var GEO_display_label respop72015;
run;

Art, CEO, AnalystFinder.com

 

View solution in original post

8 REPLIES 8
Shmuel
Garnet | Level 18

Having a char type variable you can use either of next functions:

-  UPCASE will change all charcters into upper case (capital) letters

-  LOCASE will change all characters into low case letters

 

syntax:  var = upcase(var);  same with locase.

 

You can change 1st letter only by:

     substr(var,1,1) = upcase(substr(var,1,1));

elaine00
Calcite | Level 5
How do I print it if the letter I selected is not in the first position?
novinosrin
Tourmaline | Level 20

@elaine00wrote:

How do I print a variable containing capital letter X?

I have no idea how to write the code, please help. 


 

 

Do you mean 

 

data example;

length var $50;

var='Xgjhhkj';

output;

var='iuyuiuioX';

output;

var='trt';

output;

run;



data wanted_output;

set example;

if index(var,'X')>0;
 put var=;

run;

 

elaine00
Calcite | Level 5
It is a dataset, I am supposed to print all the obs that containing the capital letter X of a variable (there are many variable and obs).
novinosrin
Tourmaline | Level 20

Ok, Can you please post a sample of your dataset like 10 obs/vars with values and your expected output. Also, when you say "print" , please let the community know whether you want the output in a sas dataset or ods or printed values in the log. This will help the community to not assume your requirement. Thank you!

elaine00
Calcite | Level 5

Thank you. The question says, Print the population of the states containing the letter C (Capital C, case sensitive) in their GEO_display_label. and I attached the csv file

art297
Opal | Level 21

Assuming respop72015 represents the population in 2015, then here is one way to do it:

data have;
  infile '/folders/myfolders/USPOP.csv' dlm=',' dsd lrecl=200 firstobs=2;
  informat GEO_id $12.;
  informat GEO_display_label $40.;
  input GEO_id GEO_display_label respop72010-respop72015;
run;

proc print data=have (where=(index(GEO_display_label,'C') and
                      GEO_id ne '0400000US11'));
  var GEO_display_label respop72015;
run;

Art, CEO, AnalystFinder.com

 

elaine00
Calcite | Level 5
Thank you! It really helps!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 8 replies
  • 1196 views
  • 0 likes
  • 4 in conversation