BookmarkSubscribeRSS Feed
michokwu
Quartz | Level 8

Hi,

I am using the sas enterprise guide

I have a dataset that contains a list of codes for first degree programs, all educational program titles and their codes ie. three columns; fd_code, program_title, pr_code

How do I look up fd_code from the pr_code column and create a new column with the corresponding program title

 

See below

 

fd_codeprogram_titlepr_code
2404Aerospace Engineering2401
5001Anthropology And Archeology5502
5001Applied Mathematics3701
2403Architectural Engineering2403
3701Architecture1401
5223Area Ethnic And Civilization Studies1501

 

Thank you

10 REPLIES 10
Astounding
PROC Star

If you want the program title, why use FD_CODE at all?  Why not just look up PROGRAM_TITLE based on PR_CODE?

michokwu
Quartz | Level 8

I have individual A who has a first degree with just the fd_code given, I need to search the pr_code column to know the title of his/her first degree

Astounding
PROC Star

For that, you will have to show what you want. 

 

So far, you have shown one source of data.  Clearly, you must have another source of data that you want to match with.  Give a brief example of what that other data source looks like, and what the result should be after matching.

michokwu
Quartz | Level 8

Thank you,

 

Just a column with serial_no. Its from a pubic data source, so the serial number column represents each individual 

michokwu
Quartz | Level 8
Serial_nofd_codeprogram_titlepr_code
20120000001502404Aerospace Engineering2401
20120000001945001Anthropology And Archeology5502
20120000001945001Applied Mathematics3701
20120000002952403Architectural Engineering2403
20120000003203701Architecture1401
20120000003455223Area Ethnic And Civilization Studies1501
Patrick
Opal | Level 21

@michokwu wrote:

I have individual A who has a first degree with just the fd_code given, I need to search the pr_code column to know the title of his/her first degree


In the sample data you've posted an fd_code doesn't map 1:1 to a pr_code. So if you've only got the fd_code how do you think you'd be able to determine the pr_code?

5001 Anthropology And Archeology 5502
5001 Applied Mathematics 3701

 

 

michokwu
Quartz | Level 8

The pr_code maps to the program_title.

If I need to know the program title for individual A's first degree, I will need to take the fd_code as given, and search the pr_code to come up with the program title.

My thoughts.

ballardw
Super User

If you have your pr_code and Program_title in a data set then easiest may be to make a custom format. Below I 1) create a data set using your example data, 2) add the variables that Proc Format requires to create a format, 3) use the data set created to create format using the CNTLIN option and 4) print the original have data set values of the PR_code using the format created.

 

data have;
   infile datalines dlm='|';
   informat fd_code $4. program_title $50. pr_code $4.;
   input fd_code program_title pr_code ;
datalines;
2404|Aerospace Engineering|2401 
5001|Anthropology And Archeology|5502 
5001|Applied Mathematics|3701 
2403|Architectural Engineering|2403 
3701|Architecture|1401 
5223|Area Ethnic And Civilization Studies|1501 
;
run;

data temp;
   set have;
   fmtname='PROGRAM_TITLE';
   type='C';
   start=pr_code;
   label=program_title;
run;

proc format library=work cntlin=temp;
run;

Proc print data=have label;
   var pr_code;
   format pr_code $program_title.;
   label pr_code='Formatted PR_Code';
run;
michokwu
Quartz | Level 8

Thanks. I received error message: ERROR: You are trying to use the character format $PROGRAM with the numeric variable Pr_Code in data set WORK.PATH.

 

Also, the solution does not address how to find and match the value. I tried to assign the value of pr_code to program_title but could not. 

I saw a similar but not exact discussion https://communities.sas.com/t5/SAS-Programming/How-to-assign-a-column-value-based-on-another-column/... but still does not answer my question

ballardw
Super User

@michokwu wrote:

Thanks. I received error message: ERROR: You are trying to use the character format $PROGRAM with the numeric variable Pr_Code in data set WORK.PATH.

 

Also, the solution does not address how to find and match the value. I tried to assign the value of pr_code to program_title but could not. 

I saw a similar but not exact discussion https://communities.sas.com/t5/SAS-Programming/How-to-assign-a-column-value-based-on-another-column/... but still does not answer my question


Since you did not provide data in the form of a data step I have to guess whether values like pr_code are numeric or character. Most things named "code", like Zipcode, are identifiers and generally are not used for numeric calculation and hence are character.

Remove the quotes around the pr_code values in the format, remove the $ from both the Proc format definition and the proc print.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 10 replies
  • 4111 views
  • 0 likes
  • 4 in conversation