@Babloo wrote:
There is a variable called Entity_Id in SAS dataset and for that variable I have to apply the format where the format is located in the SQL table. I don't want to create the SAS dataset of that SQL table.
How can I apply the format from SQL to SAS?
You will either need to explain better and/or provide a concrete example.
What do you mean by "apply the format" to ENTITY_ID? Do you mean use a format to convert the values of ENTITY_ID into some other text?
What is an "SQL table"? How is that different than a SAS dataset? Are you querying some external database? If so how are you going to use information from that external database without reading it?
You could use the values from that external table to define a format. Assuming you have made a libref MYSQLLIB that points to your database/schema and the mapping data is in a table named MY_MAPPING_TABLE. Also assuming the ENTITY_ID is a character string (why would you use a number for something you would never want to do arithmetic with?) then code might look like this:
proc sql;
create table fmt as
select distinct
'$new_entity_id' as fmtname
, old_entity_id as start
, new_entity_id as label
from mysqllib.my_mapping_table
order by 1,2
;
quit;
proc format cntlin=fmt; run;
data want ;
set have ;
new_entity_id = put(entity_id,$new_entity_id.);
run;
But you cannot define a format in SAS without actually reading the data that defines it into SAS.
If the source table is large and the SAS table that has the values that need mapping is small it might be fastest to just pull the values you need from the external database.
I don't want to create the SAS dataset of that SQL table.
You'll have to unfortunately, or at minimum create the lookup table.
@Babloo wrote:
May I know how can I create the look up table?
Once again, Maxim 1: Read the Documentation.
Input Control Data Set in PROC FORMAT.
You need 5 variables:
@Babloo wrote:
May I know how can I create the look up table?
Same way you reference any other table, Tom's code is correct, assuming we've interpreted your question correctly.
@Babloo wrote:
I don't want to create the SAS dataset of that SQL table.
Then use a view. But since cntlin datasets are quite small by nature (only 5 columns needed), there's no need to avoid building the input data as a dataset.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.