How do I print a variable containing capital letter X?
I have no idea how to write the code, please help.
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
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));
@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;
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!
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
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
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.