Hi everyone - a bit newer to SAS and running into a problem trying to adapt someone's older code. Essentially I have a character variable with responses, and am coding in skips to it. e.g. Add skip coded 777 into the open text variable OPENTEXT1 if responses are blank OPENTEXT1 has character responses maxing out at 161 characters, proc contents show format=161 informat=$161. Check responses with proc freq, all 777 and responses are normal Then I create a "label" using the proc format function with value to label the skip and keep responses proc format; value OPENTEXT '777'="Skip"; run; data dataset1; set dataset; format OPENTEXT $OPENTEXT. proc freq, this time 777 show "SKIP" but other responses truncated to 4 characters I checked proc contents, and it is still showing format and informat still remaining at the same length. Any help appreciated
... View more
Hello, I have a couple of case when statements that will be used in about 18 different proc SQL programs within a project. Rather than copying and pasting the case when statements in each program, I'm wondering if there's a way for me to create a macro that stores the case when statements so that I can reference the macro from each of the programs. The first macro is quite simple. I have a variable that has a few invalid values that must be mapped to valid ones. However, the vast majority of observations can remain as they are. My case when statement is structured as follows: (CASE /*if variable is an invalid value, return its valid equivalent*/
WHEN VARIABLE = INVALID_VALUE1 THEN VALID_VALUE1
WHEN VARIABLE = INVALID_VALUE2 THEN VALID_VALUE2
... /*otherwise, return the variable as-is*/
ELSE VARIABLE END) as VARIABLE_CORRECTED, This is what I've tried, but it didn't work: %macro variable_crosswalk(variable);
%if &variable = 'invalid_value1' %then %let ;
&variable = 'valid_value1'; %end;
%else %if &variable = 'invalid_value2' %then %do;
&variable = 'valid_value2'; %end;
...
%else %do;
&variable
%end;
%mend; The second case when statement I'd like to store in a macro is a little more complicated. It uses several different race/ethnicity fields to calculate a person's race. It's structured as follows: (case
when race1 = 1 then 'Race 1'
when race8 = 2 then 'Race 2'
...
when race1 = 1 and race2 = 2 then 'Two or More Races' when race1 = 1 and race3 = 3 then 'Two or More Races' /*all other possible race combinations*/
...
else 'Unknown' end) as Race_Ethnicity, Is there a way for me to store one or both of the case when statements above as macros that can be accessed from all 18 programs in my project? If so, can someone help me with the syntax? Thanks for any assistance you can provide!
... View more
Hi all, I have successfully created an annotated state map from geocoded address info using the states map. However, when I try to use the county map data set, it appears that the geocoding output does not match what information in the county map dataset. Here is a small program to illustrate the difficulty. Code doesn't get past proc gproject. It seems that the length of x and y of the map do not match the length of x and y in the geocoded output. thanks! Phil : libname lookup "D:\Documents\desi2023\frlanalyses\geocodedata__2006__ZIP4_Geocode_Data\data"; data zips; input c zip; anno_flag=1l cards; 1 65203 2 65211 3 65201 ; proc geocode /* Invoke geocoding procedure */ method=plus4 /* Specify geocoding method */ lookup=lookup.zip4 /* Lookup data from MapsOnline */ data=zips /* Input data set to geocode */ out=geocodedzips; /* Specify name of Output data set of locations */ run; data mocounties;set maps.counties;if state=29; data mocounties;set mocounties geocodedzips;run; proc gproject data=mocounties out=MOCountiesP; id state ; run; data my_map locations; set mocountiesP; if anno_flag=1 then output locations; else output my_map; run; data anno_locations; set locations; if c=1 then color="red"; if c=2 then color="bib"; if c=3 then color="viyg"; if c=4 then color="bippk"; xsys='2'; ysys='2'; hsys='3'; when='a'; function='pie'; rotate=360; size=.5; style='psolid'; output; length html $300; html='title='||quote(trim(left(citystate))||'0d'x||trim(left(put(zip,z5.)))); style='pempty'; color='deb'; output; run; pattern1 v=e; proc gmap data=mymap map=mymap anno=anno_locations; id county; choro segment / coutline=black levels=1 nolegend coutline=gray99;run;
... View more
I have a dataset with two columns v1 and v2. V1 consists of labels such as "Spam" or "Ham" and v2 consists of texts. The error is "Proc hptmine reports ERROR: Unable to load extension: (tkparse) A computational component or a required service component could not be loaded in SAS enterprise miner" when I turn the text parsing node.
... View more
Esteemed Advisors:
I am trying to interleave two datasets with a condition that the resulting dataset contains only observations that can be found in both of the two datasets.
Below is exemplar code to illustrate the problem. If you run this code and inspect dataset interleave2 you will see that for a group of 3 observations where target=1, two came from Random_A and one came from Random_B. Likewise, for a group of three observations where target=2, two came from Random_B and one came from Random_A. All of these observations need to be retained in the desired dataset.
For the group of 3 observations where target=3, all observations came from Random_B only. These are ones that need to be omitted. All observations for a given target that come from a single source dataset are not to be retained in the desired dataset.
The challenge for me (and now for you) is to come up with the code that will interleave Random_A and Random_B such that the resultant dataset that only contains the groups of targets that are present in both datasets.
Hope this makes sense and thanks for taking a look,
Gene
data Random_A (drop=i);
call streaminit(4786);
do i=1 to 100;
Source="A";
Target=rand("Integer",1,100);
ST=catx('/',Source,Target);
output;
end;
data Random_B (drop=i);
call streaminit(6874);
do i=1 to 150;
Source="B";
Target=rand("Integer",1,100);
ST=catx('/',Source,Target);
output;
end;
Proc sort data=Random_A;
by ST;
run;
Proc sort data=Random_B;
by ST;
run;
data interleave1;
set random_A random_B;
by ST;
run;
proc sort data=interleave1 out=interleave2 nounikey;
by target;
run;
... View more