BookmarkSubscribeRSS Feed
ZRick
Obsidian | Level 7

I want to write SAS code that can read in csv file every time it is read, number of columns maybe different.

In addition, I need to use different variables to look up different values.

let's say first time I have 3 columns, it's a look up table, use var1 - var2 to look up RF01

next time when I read in the file, it has 5 columns, use var1 - var3 to look up RF01 and RF02

So, given this situation, the column number is not fixed, and also look up column value is different too.

Any ideas?

4 REPLIES 4
manojinpec
Obsidian | Level 7

One Clarification.Var1-Var2 are two variables whcihis being used to lookup RF01. when file has 5 columns , we need to use four vairbales to look up.

Any example to explain this would be helpful

ZRick
Obsidian | Level 7

1st time, table is like this:

var1 var2      RF01

us     fin       IR

eu     tech    FX

ca     svc     sprd

2nd time, table is like this

var1 var2   var3    RF01   RF02

us    fin     swp    crv01    FX

eu    corp  sptn   crv02    sprd

gb     bnk  edotn  crv04   ir

Ksharp
Super User

Why not use proc import to import csv file.

but about your querying. I don't know which criterion you used to judge variable should be var: or RF: ?

Ksharp

ballardw
Super User

Will different iterations of this process also add any rows to your data?

I think the PROC IMPORT solution Ksharp mentioned is a good start but if you have rows added to your data there may be an issue with a variable column changing data types from numeric to string based on the content.

Suppose the first time you read the data with column 10 the values are numeric. Then in a later version added rows in column 10 now contain some text values. Proc import is likely to make that variable string.

sas-innovate-2024.png

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.

 

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