SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

How to program a macro to input a defined number to certain column?

Reply
Super Contributor
Posts: 297

How to program a macro to input a defined number to certain column?

Hello:

 

I would like to program a Macro procedure when the State name shown in the State column, it will corrospored to assign a certain number to the GEO_JUR column.  Therefore, if the same situation happens again, it will save my time.  Please see my SAS data.

However, I don't know how.   Please help.  Thanks.

 

Ying

 

%macro ASSIGNGEO(&State,GEO_JUR);
length GEO_JUR $10.;
IF &State="Alabama" THEN GEO_JUR="01";
IF &State="Alaska" THEN GEO_JUR="02";
IF &State="Arizona" THEN GEO_JUR="04";
IF &State="Arkansas" THEN GEO_JUR="05";
IF &State="California" THEN GEO_JUR="06";
IF &State="Colorado" THEN GEO_JUR="08";
IF &State="Connecticut" THEN GEO_JUR="09";
IF &State="Delaware" THEN GEO_JUR="10";
IF &State="District of Columbia" THEN GEO_JUR="11";
IF &State="Florida" THEN GEO_JUR="12";
IF &State="Georgia" THEN GEO_JUR="13";
IF &State="Hawaii" THEN GEO_JUR="15";
IF &State="Idaho" THEN GEO_JUR="16";
IF &State="Illinois" THEN GEO_JUR="17";
IF &State="Illinios" THEN GEO_JUR="17";
IF &State="Indiana" THEN GEO_JUR="18";
IF &State="Iowa" THEN GEO_JUR="19";
IF &State="Kansas" THEN GEO_JUR="20";
IF &State="Kentucky" THEN GEO_JUR="21";
IF &State="Louisiana" THEN GEO_JUR="22";
IF &State="Maine" THEN GEO_JUR="23";
IF &State="Maryland" THEN GEO_JUR="24";
IF &State="Massachusetts" THEN GEO_JUR="25";
IF &State="Michigan" THEN GEO_JUR="26";
IF &State="Minnesota" THEN GEO_JUR="27";
IF &State="Mississippi" THEN GEO_JUR="28";
IF &State="Missouri" THEN GEO_JUR="29";
IF &State="Montana" THEN GEO_JUR="30";
IF &State="Nebraska" THEN GEO_JUR="31";
IF &State="Nevada" THEN GEO_JUR="32";
IF &State="New Hampshire" THEN GEO_JUR="33";
IF &State="New Jersey" THEN GEO_JUR="34";
IF &State="New Mexico" THEN GEO_JUR="35";
IF &State="New York" THEN GEO_JUR="36";
IF &State="North Carolina" THEN GEO_JUR="37";
IF &State="North Dakota" THEN GEO_JUR="38";
IF &State="Ohio" THEN GEO_JUR="39";
IF &State="Oklahoma" THEN GEO_JUR="40";
IF &State="Oregon" THEN GEO_JUR="41";
IF &State="Pennsylvania" THEN GEO_JUR="42";
IF &State="Puerto Rico" THEN GEO_JUR="72";
IF &State="Rhode Island" THEN GEO_JUR="44";
IF &State="South Carolina" THEN GEO_JUR="45";
IF &State="South Dakota" THEN GEO_JUR="46";
IF &State="Tennessee" THEN GEO_JUR="47";
IF &State="Texas" THEN GEO_JUR="48";
IF &State="United States" THEN GEO_JUR="N1";
IF &State="Utah" THEN GEO_JUR="49";
IF &State="Vermont" THEN GEO_JUR="50";
IF &State="Virginia" THEN GEO_JUR="51";
IF &State="Washington" THEN GEO_JUR="53";
IF &State="West Virginia" THEN GEO_JUR="54";
IF &State="Wisconsin" THEN GEO_JUR="55";
IF &State="Wyoming" THEN GEO_JUR="56";

IF &State="American Samoa" THEN GEO_JUR="60";
IF &State="Guam" THEN GEO_JUR="66";
IF &State="Northern Mariana Islands " THEN GEO_JUR="69";
IF &State="Republic of Palau" THEN GEO_JUR="70";
IF &State="U.S. Virgin Islands " THEN GEO_JUR="78";
IF &State="Virgin Islands " THEN GEO_JUR="78";
IF &State="N1" THEN GEO_JUR="N1";
run;
%Mend;

data GEOMACRO1;
set GEOMACRO;
?????
run;

Super User
Posts: 17,907

Re: How to program a macro to input a defined number to certain column?

Please dont post the same question twice.
Super Contributor
Posts: 297

Re: How to program a macro to input a defined number to certain column?

I didn't know it's the same tech support people,  I think if I post in the different place,  I could get different answer so that I could learn about the different tricks.   Besides, not all of the solutions are suitable for my situation.

Super User
Posts: 10,538

Re: How to program a macro to input a defined number to certain column?


ybz12003 wrote:

I didn't know it's the same tech support people,  I think if I post in the different place,  I could get different answer so that I could learn about the different tricks.   Besides, not all of the solutions are suitable for my situation.


 

Actually a majority of the help posts are volunteers, not tech support.

Also an additional issue is that a solution, once accepted, may not be found by someone searching an finding one post but not the other. Plus some communication issues with responding to the same questions in multiple posts or more entertaining answering a question posed in post in the other part of the thread.

Super User
Posts: 17,907

Re: How to program a macro to input a defined number to certain column?

+1000 -> Actually a majority of the help posts are volunteers, not tech support.

Super User
Posts: 17,907

Re: How to program a macro to input a defined number to certain column?

Also, on the same train of thought, please mark questions as answered when you have a solution. It doesn't look like any of your previous questions were marked as answered. 

Super Contributor
Posts: 297

Re: How to program a macro to input a defined number to certain column?

Thanks for all of your kindness reply and volunteer.   I'm new here, don't too much about rules.  

Ask a Question
Discussion stats
  • 6 replies
  • 502 views
  • 3 likes
  • 3 in conversation