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

For the last two questions, I was stuck on how to start:

😎 Update the name variable by adding the airport code column after the first word of airport name, keep
a space in between.  

9)Split the location variables into two columns, city and state; output the airport name (the variable we
used before updating), city and state variables only.  

 

Do we have to use merge for question 8? What does an example of this look like?

How do I go about writing question 9?

Tom
Super User Tom
Super User

That does not look like a CSV file.  It does not have commas between the values.  Perhaps they are using TAB as the delimiter instead?  You really should always use the DSD option when reading delimited files. And always use the TRUNCOVER option when all of the data for one observation is on one line of the text file being read.

 

Reading RANK as a character variable will not let it sort properly.  '12' will sort before '2' since it starts with the digit 1 which comes before the digit 2.

JoshuaG
Calcite | Level 5

Was able to implement those fixes for question 7. Still stuck on how to approach question 8 and question 9

Kurt_Bremser
Super User

@JoshuaG wrote:

I was able to fix question 6 using trim. I wanted to see if question 7 looks good:

 

7) Read in the cargo.csv data file and output the variables in order of rank, name, code, location, year
from 2014 to 2011;

 

Cargo File:

1 Memphis International AirportMemphis, TennesseeMEM ######## ######## ######## ########
2 Ted Stevens Anchorage International AirportAnchorage, AlaskaANC ######## ######## ######## ########
3 Louisville International AirportLouisville, KentuckySDF ######## ######## ######## ########
4 O'Hare International AirportChicago, IllinoisORD ######## ######## ######## ########
5 Miami International AirportMiami, FloridaMIA ######## ######## ######## ########
6 Indianapolis International AirportIndianapolis, IndianaIND ######## ######## ######## ########
7 Los Angeles International AirportLos Angeles, CaliforniaLAX ######## ######## ######## ########
8 Cincinnati/Northern Kentucky International AirportCincinnati, OhioCVG ######## ######## ######## ########
9 John F. Kennedy International AirportNew York, New YorkJFK ######## ######## ######## ########
10 Dallas/Fort Worth International AirportFort Worth, TexasDFW ######## ######## ######## ########

Code:

/*Question7*/
Data cargo;
length rank $2. name $50. location $50. code $3.;
infile '/home/u62108616/sasuser.v94/S325/cargo.csv' dlm = ','; 
input rank $ name $ location $ code $ wt2014 wt2013 wt2012 wt2011;
Format wt2014 COMMA15.0 wt2013 COMMA15.0 wt2012 COMMA15.0 wt2011 COMMA15.0;
run;

What you show is not a csv file (no commas). The fact that all the numbers are replaced by ######## lets me suspect you did not follow my specific request to use a TEXT EDITOR to open the file.

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 18 replies
  • 1228 views
  • 0 likes
  • 3 in conversation