BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Cynthia_sas
SAS Super FREQ

Hi:

As another example of a lookup technique, my tendency would be to make a user-defined format from the file with the name1-name3 and then to use that format when reading data file A to make the NEWNAME variable.

 

Something like this:


data fmt_examp(keep=fmtname start end label);
  length start $50 end $50 label $50 ;
  retain fmtname '$namef' type 'C';
length name1 name2 name3 $50;
infile datalines dlm=',' dsd;
input name1 $ name2 $ name3 $;
label=name1;
start=name1; end=name1;
output;
start=name2; end=name2;
output;
start=name3; end=name3;
output;
datalines;
"International Business Machines","IBM","IBM Corp."
"Apple","Apple Inc.","AAPL"
"Google LLC","GOOGL","Google"      
;
run;

proc format cntlin=fmt_examp fmtlib;
run;

data a;
length name newname $50;
input id $ name $;
newname = put(name,$namef.);
cards;
01        IBM
02        Apple
;
run;

proc print data=a;
title 'Using format for lookup';
run;
 
 

 

(There's always more than 1 way to do things in SAS.)

 

Cynthia

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 15 replies
  • 1844 views
  • 2 likes
  • 5 in conversation